Apps & Builds
oc new-app <git-url>
Detect, build and deploy source
oc new-app --image=<img> --name=<name>
Deploy an existing image
oc new-app <builder>~<git-url>
Build source with a builder image
Example: nodejs~https://github.com/<org>/<repo>
oc new-app <img> -e <KEY>=<value>
Set env vars on create
oc new-app --template=<tpl> -p
<KEY>=<value>
Instantiate a template
oc new-app --search <term>
Search images and templates
oc new-build <git-url>
BuildConfig only, no deploy
oc new-build --strategy=docker --binary
--name=<name>
Binary Dockerfile build
oc start-build <bc>
Start a build
oc start-build <bc> --follow
Start and stream build log
oc start-build <bc> --from-dir=<dir>
--follow
Build from local files
Uploads the directory instead of cloning the repo.
oc start-build <bc> --wait
Wait; non-zero exit on failure
oc cancel-build <build>
Cancel a running build
oc logs -f bc/<bc>
Follow latest build log
oc get builds
List builds
oc process -f <template> -p <KEY>=<value>
| oc apply -f -
Render a template and apply
Deploy & Rollout
oc rollout status deploy/<name>
Watch a rollout
oc rollout restart deploy/<name>
Restart all pods
oc rollout undo deploy/<name>
Roll back one revision
oc rollout history deploy/<name>
List revisions
oc rollout latest dc/<name>
New rollout of a DeploymentConfig
oc set env deploy/<name>
<KEY>=<value>
Set env var (triggers rollout)
oc set env deploy/<name> --list
Show env vars
oc set env deploy/<name>
--from=secret/<secret>
Env from a secret
oc set volume deploy/<name> --add -t pvc
--claim-name=<pvc> -m <path>
Mount a PVC
oc set triggers deploy/<name>
--from-image=<is>:<tag> -c
<container>
Redeploy on image change
Images
oc get is
List image streams
oc import-image <is>:<tag> --from=<img>
--confirm
Import an external image
oc import-image <is>
Re-check source for updates
oc tag <is>:<tag>
<is>:<newtag>
Point a tag at an image
Promote dev to prod: workloads with an image trigger on the
new tag redeploy.
oc tag --source=docker <img>
<is>:<tag>
Track an external image
oc registry login
Log in to the integrated registry
oc image mirror <src> <dest>
Copy image between registries
oc secrets link <sa> <secret> --for=pull
Use a pull secret for a SA
Debug & Files
oc rsh <pod>
Shell in first container
oc rsh -c <container> <pod>
Shell in a named container
oc rsh <pod> <cmd>
Run one command
oc rsync <dir>/ <pod>:<path>
Copy local dir to pod
oc rsync <pod>:<path> <dir>
Copy from pod
oc debug deploy/<name>
Copy pod and open a shell
Probes are disabled and the command replaced, so crashing pods
stay up.
oc debug deploy/<name> --as-root
Debug copy running as root
oc debug node/<node>
Root shell on a node
Run chroot /host to use the node's own tools.
oc extract secret/<name> --to=-
Print secret values decoded
Admin (oc adm)
oc adm policy add-role-to-user <role>
<user>
Grant role in project
oc adm policy add-role-to-user <role> -z
<sa>
Grant role to service account
oc adm policy add-cluster-role-to-user <role>
<user>
Grant cluster-wide role
oc adm policy add-scc-to-user <scc> -z
<sa>
Allow SA an SCC
Example SCCs: restricted-v2, anyuid, privileged.
oc adm must-gather
Collect cluster data for support
Writes ./must-gather.local.<random>.
oc get co
Cluster operator health
oc get clusterversion
Cluster version and update state
oc adm top node
Node CPU and memory
oc adm cordon <node>
Mark node unschedulable
oc adm drain <node> --ignore-daemonsets
Evict pods for maintenance
oc adm upgrade
Show available updates