Red Hat Openshift Cheat Sheet

Vanakkam all

For students and corporate professionals who are preparing for exam and interview , refer these commands to start with and practice. More to come on commands related to different industry focus.

Login to an OpenShift Cluster:

oc login -u username -p password

List the common objects

oc api-resources
oc get nodes
oc get pods
oc get deployment
oc get deploymentconfig
oc get service
oc get endpoint
oc get route
oc get replicaset
oc get daemonset
oc get namespace
oc get quota
oc get limits
oc get projects
oc get secrets
oc get configmap
oc get persistentvolume
oc get persistentvolumeclaim
oc get storageclass
oc get job
oc get cronjob
oc get clusterrole
oc get users
oc get groups
oc get serviceaccount
oc get role
oc get hpa
oc get machineconfig

List the common output options of an object

oc get nodes -o wide
oc get pods -o wide
oc get deployment -o wide
oc get service -o wide

oc get pods <pod-name> -o yaml
oc get pods <pod-name> -o json
oc get  deployment <deployment-name> -o yaml
oc get service <service-name> -o yaml

Edit options

oc edit node <node-name>
oc edit deployment <deployment-name>
oc edit service <service-name>
oc edit route <route-name>


oc logs <pod-name>
oc get ep
oc describe pod <pod-name>
oc describe deployment <deployment-name>

Help options

oc create deployment --help
oc create route --help
oc create service --help
oc create secret --help
oc create configmap --help
oc create serviceaccount --help
oc adm policy --help
oc scale --help
oc autoscale --help

List All Projects:

oc get projects

Switch Project:

oc project my-project

Create a New Application:

oc new-app

Get Pods:

oc get pods

Watch Pods in Real Time:

oc get pods -w

Describe Pod:

oc describe pod <pod_name>

Execute Command in Pod:

oc exec <pod_name> -- df-k

Logs & Debugging

Get Logs for a Pod:

oc get pods  
oc logs <pod_name>

Follow Logs in Real Time:

oc logs -f <pod_name>

Debug a Pod:

oc debug pod/<pod_name>

Managing Resources

Create Resource (e.g., Deployment, Service) from a File:

oc create -f <filename.yaml>

If you don’t know to write yaml , use this

oc get deployment todo-angular -o yaml    
oc get deployment todo-angular -o yaml > mydeployment.yaml
ls -lrt

Get Deployments:

oc get deployment

Scale a Deployment:

oc scale deployment todo-angular --replicas=3

Edit Resource:

oc edit <resource_type>/<resource_name>
Example :
oc edit deployment/todo-angular

Delete Resource:

oc delete <resource_type> <resource_name>
Example :
oc delete deployment todo-angular
oc get deployment

Create a New Project:

oc new-project <project_name>
Example :
oc new-project test

Grant Role to User in Project:

oc policy add-role-to-user <role> <username> -n <project_name>
Example :
oc policy add-role-to-user admin test-user -n test

Get Users:

oc get users


Expose Service Externally:

oc get service
oc expose svc/<service_name>
Example :
oc expose svc/todo-angular

Get Route:

oc get route


oc help