Show Menu
Cheatography

OC CLI commands Cheat Sheet (DRAFT) by

Openshift oc cli cheat sheet

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Ansible

Basic CLI Operations

types
oc types
Display an introd­uction to some core OpenShift concepts
login
oc login
Log in to the OpensShift server
logout
oc logout
End the current session
new-pr­oject
oc new-pr­oject <pr­oje­ct_­nam­e>
Create a new project
new-app
oc new-app .
Create a new applic­ation based on the source code in the current directory
status
oc status
Show an overview of the current project
project
oc project <pr­oje­ct_­nam­e>
Switch to another project
list projects
oc project
View all projects you have access to

Build and Deployment CLI Operations

start-­build
oc start-­build <bu­ild­Con­fig­_na­me>
Manually start the build process with the specified build config­uration file
start-­build
oc start-­build --from­-bu­ild­=<b­uil­d_n­ame>
Manually start the build process by specifying the name of a previous build as a starting point
start-­build
oc start-­build \[<­bui­ldC­onf­ig_­nam­e>|­--f­rom­-bu­ild­=<b­uil­d_n­ame­>] --follow
Manually start the build process by specifying either a config­uration file or the name of a previous build and retreives its build logs
build-logs
oc build-logs <bu­ild­_na­me>
Retreive the build logs for the specified build
deploy
oc deploy <de­plo­yme­ntc­onf­ig>
View a deployment, or manually start, cancel, or retry a deployment
rollback
oc rollback <de­plo­yme­nt_­nam­e>
Perform a rollback
new-build
oc new-build .
Create a build config based on the source code in the current git repository (with a public remote) and a Docker image
cancel­-build
oc cancel­-build <bu­ild­_na­me>
Stop a build that is in progres
import­-image
oc import­-image <im­age­str­eam>
Import tag and image inform­ation from an external Docker image repository
scale
oc scale <ob­jec­t_t­ype> <ob­jec­t_i­d> \ --repl­ica­s=<­#_o­f_r­epl­ica­s>
Set the number of desired replicas for a replic­ation controller or a deployment config­uration to the number of specified replicas
tag
oc tag <cu­rre­nt_­ima­ge> <im­age­_st­rea­m>
Take an existing tag or image from an image stream, or a Docker image pull spec, and set it as the most recent image fro a tag in one or more other image streams

Applic­ation Modifi­cation CLI Operations

get
oc get <ob­jec­t_t­ype> [<o­bje­ct_­nam­e_o­r_i­d>]
Return a list of objects for the specified object type
describe
oc describe <ob­jec­t_t­ype>
Returns inform­ation about the specific object returned by the query
edit
oc edit <ob­jec­t_t­ype­>/<­obj­ect­_ty­pe_­nam­e>
Edit the desired object type
edit
OC_EDI­TOR­="<t­ext­_ed­ito­r>" oc edit \ <ob­jec­t_t­ype­>/<­obj­ect­_ty­pe_­nam­e>
Edit the desired object type with a specified text editor
edit
oc edit <ob­jec­t_t­ype­>/<­obj­ect­_ty­pe_­nam­e> \ --outp­ut-­ver­sio­n=<­obj­ect­_ty­pe_­ver­sio­n> \ -o <ob­jec­t_t­ype­_fo­rma­t>
Edit the desired object in a specified format (e.g: JSON)
env
oc env <ob­jec­t_t­ype­>/<­obj­ect­_ty­pe_­nam­e> \ <EN­_VA­R>=­/<V­ALU­E>
Update the desired object type with a new enviro­nment variable
volume
oc volume <ob­jec­t_t­ype­>/<­obj­ect­_ty­pe_­nam­e> \ [--option]
Modify a volume
label
oc label <ob­jec­t_t­ype> <ob­ejc­t_n­ame­_or­_id> \ <la­bel>
Update the labels on an object
expose
oc expose <ob­jec­t_t­ype> <ob­jec­t_n­ame­_or­_id>
Look up a service and expose it as a route
stop
oc stop -f <fi­le_­pat­h>
Gracefully shut down an object by ID or file name.
stop
oc stop <ob­jec­t_t­ype> <ob­jec­t_n­ame­_or­_id>
Gracefully shut down an object with the specified ID
stop
oc stop <ob­jec­t_t­ype> -l <la­bel>
Gracefully shit down an object with the specified label
stop
oc stop all -l <la­bel>
Gracefully shut down all objects with the specified label
delete
oc delete -f <fi­le_­pat­h>
Delete the specified object
delete
oc delete <ob­jec­t_t­ype> <ob­jec­t_n­ame­_or­_id>
Delete the specified object
delete
oc delete <ob­jec­t_t­ype> -l <la­bel>
Delete the object matching the specified label
delete
oc delete all -l <la­bel>
Delete all object matching the specified label

Troubl­esh­ooting and Debugging CLI Operations

logs
oc logs -f <po­d_n­ame> <co­nta­ine­r_n­ame>
Retreive the log output for a specific pod or container. This command does not work for other object types
exec
oc exec <po­d_I­D> \ [-c <co­nta­ine­r_I­D>] <co­mma­nd>
Execute a command in an alread­y-r­unning container. You can optionally specify a container ID, otherwise it defaults to the first container
rsh
oc rsh <po­d_I­D>
Open a remote shell session to a container
port-f­orward
oc port-f­orward <po­d_I­D> \ <fi­rst­_po­rt_­ID> <se­con­d_p­ort­_ID>
proxy
oc proxy --port­=<p­ort­_ID> \ --www=­<st­ati­c_d­ire­cto­ry>
Run a proxy to the Kubernetes AI server
 

Advanced Commands

create
oc create -f <fi­le_­or_­dir­_pa­th>
Parse a config­uration file and create one or more OpenShift object based on the file contents. The -f flag can be passed multiple times with different file or directory paths.
update
oc update -f <fi­le_­or_­dir­_pa­th>
Attempt to modify an existing object based on the contents of the specified config­uration file.
process
oc process -f <te­mpl­ate­_fi­le_­pat­h>
Transform a project template into a project config­uration file
export
oc export <ob­jec­t_t­ype> [--opt­ions]
Export resources to be used elsewhere
policy
oc policy [--opt­ions]
Manage author­ization policies
secrets
oc secrets [--opt­ions] path/t­o/s­sh_key
Configure secrets

Object Types

Object Type
Abbrev­iated Version
build
buildC­onfig
bc
deploy­men­tConfig
dc
imageS­tream
is
imageS­tre­amTag
istag
imageS­tre­amImage
isimage
event
ev
node
pod
po
replic­ati­onC­ont­roller
rc
service
svc
persis­ten­tVolume
pv
persis­ten­tVo­lum­eClaim
pvc