Commands cheatsheet

Connect to Openshift cluster:

These commands are used for connecting to an Openshift cluster:

  • oc login: Connects to an Openshift cluster with a username and a password or a token.

    I recommend you use a token because you can make it expire in case of emergency (For example: Data breach). The easiest way to get the token is to log in to the web interface of Openshift, click on your username, and select “Copy login command”


      oc login --server=[URL OF OCP CLUSTER] -u=[USERNAME] -p=[PASSWORD]
      oc login --server= -u=Branyac -p=FakePassw0rd
      oc login --server=[URL OF OCP CLUSTER] --token=[TOKEN]
      oc login --server= --token=sha256~RpB3qYXAMeNj7vfajP5YVCJR0c-RWVhBv-S45Bpx-II
  • oc logout: Disconnects from Openshift Server

Select Openshift project:

A project is a logical space for isolating resources like deployments, secrets, or role bindings to restrict access and/or configure quotas.

  • oc projects: Shows the list of the projects of the Openshift Cluster.

  • oc project: When executing this command without parameters shows the name of the current Openshift project where the commands will be applied. You can pass a project name as parameter to switch to that project.

    I recommend executing always oc project before other commands to ensure you are in the right project.


      oc project
      oc project [PROJECT_NAME]
      oc project thingsandcode-web

List resources

  • oc get: Shows the list of resources of an Openshift project or cluster (depending on the resource type) and basic information about it.

    To get a list of allowed resource types for listing execute the command oc api-resources


      oc get [RESOURCE TYPE]
      oc get pods
      oc get rolebindings
      oc get routes

Access pods

  • oc rsh: Opens remote console to a pod that is in execution. You can add a command at the end to execute it directly in the pod.


      oc rsh [POD NAME]
      oc rsh svc-frontend-01
      oc rsh [POD NAME] [COMMAND]
      oc rsh svc-frontend-01 bash

Edit quotas

  • oc scale: Sets the number of desired replicas for a deployment.




Sergio Monedero

I am excited to share my knowledge and insights on programming and devops through this personal website. I am a lifelong learner with a passion for technology, and I enjoy staying up-to-date on the latest industry trends.

Keep in touch with Me: SergioCoder@LinkedIn | Branyac@Github