Sunday, 10 May 2020

Managing Openshift resources using oc command-line tool

Openshift Container Platform, as already described in our post can be managed using:
  • the web console
  • a command line tool, called oc

In this guide, we'll analyze in deep how to modify and manage Openshift resources using the oc command.

Installing oc command-line tool.

When you install Openshift, the oc client is automatically installed on all the nodes of the cluster.
If you need, you can also install oc on another external node, from which you desire to manage the cluster.

  • If you're using RHEL, you can install it using the command:

    sudo yum install atomic-openshift-clients




Let's review all the main commands.

 command  action
  oc login https://master.org.com -u admin -p mypass  login into Openshift cluster as admin, with password mypass
 oc logout  logout from Openshift
 oc whoami  check current user
 oc new-project myproject  create a new-project named myproject
 oc delete project myproject  delete the project myproject
 oc status  check the status of the cluster you have been logged to
 oc get all   get all the most important resources of the cluster
 oc get <pods | deployments | routes |  --->  get the specified resource in the current project
 oc describe <resource_name>  get all the information about a specific resource
  oc export <resource_name>  export the definition of a resource, for backup use, in YAML format
  oc create  <resource_type> <resource_name>  create the specific resource 
  oc exec  similar to docker exec, execute commands inside a container
 oc rsh <pod_name>  open a remote shell session on a container
  oc get events   get information about life-cycle events in the current project,
 as pod creation and deletion, scheduling and nodes status
  oc logs <pod_name>  retrieve pod logs
  oc rsync <pod_name>:<pod_dir> <local_dir> -c <container_name>  copy the content from a directory of a pod into a local directory
 oc rsync <local_dir> <pod_name>:<pod_dir> -c <container_name>  copy the content of a local directory to a directory of a pod
 oc port-forward <pod_name> <local_port>:<remote_port>  forward a local port to a pod




4 comments: