oc Cheat Sheet

 

oc is the primary command line for OpenShift. It includes tools to build, deploy, and administer containers.

Logging in

oc login -u=<username> -p=<password> --server=<your-openshift-server> --insecure-skip-tls-verify

Switch to a specific project or log in directly to a project:

oc project <myproject>
oc login -n <myproject>

Building and deploying applications

Build code or a Dockerfile in a Git repo:

oc new-app centos/ruby-22-centos7~https://github.com/openshift/ruby-ex.git

Build from a template:

oc new-app --template=myproject/mytemplate -p=<param_name>=<param_value>

Create other objects from a file:

oc create -f myobject.yaml -n <myproject>

Update an existing object:

oc patch svc mysvc --type merge --patch '{"spec":{"ports":[{"port": 8080, "targetPort": 5000 }]}}'

Accessing running applications

oc exec <mypod> cat /opt/app-root/myapp.config
oc rsh <mypod
oc debug dc <mydc>

Common commands

oc status
oc logs pod <mypod>
oc get pods --all-namespaces
oc describe pod <mypod>
oc get services --sort-by=.metadata.name
oc delete all -l app=tomcat
oc delete pod <mypod> --grace-period=0
oc export bc,dc,is,svc --as-template=myapp.yaml

Scaling applications

oc scale dc <mydc> --replicas=5
oc autoscale dc/app-cli --min 2 --max 5 --cpu-percent=75

Administrative operations using the adm subcommand

Manage user roles:

sitemap