Combined Cheat Sheet
Combined Cheat Sheet
# Running Containers
# Start a container based on an image ID. Get the ID from docker images.
# control-c will stop the container for all of these docker run commands.
docker run -it <your-image-id>
# Stopping Containers
# Log out
oc logout
# Project Basics
# oc rsh will work with any Pod name from oc get pods
oc rsh <pod name>
# Delete all application resources using labels (get them from oc describe)
oc delete all -l app=hello-world
# List triggers
oc set triggers dc/<dc name>
# Deployment Hooks
# General syntax
oc set deployment-hook dc/<dc name> \
(--pre, --post, or --mid) \
-c <container name to execute hook in>
-- <command to execute for the hook>
strategy:
type: Recreate
# General syntax
oc set probe dc/<dc name> (--liveness or --readiness) (--open-tcp, --get-url, or --
for a command)
# Example: Add a liveness probe that opens TCP port 8080 for its test
oc set probe dc/hello-world --liveness --open-tcp=8080
# Example: Add a readiness probe that requests localhost port 8080 with the path
/health/readiness for its test
oc set probe dc/hello-world --readiness --get-url=http://:8080/health/readiness
# Example: Add a readiness probe that runs "exit 0" inside the container as its
test
oc set probe dc/hello-world --readiness -- exit 0
# Example
oc new-build https://gitlab.com/practical-openshift/hello-world.git
# Start a build
oc start-build bc/hello-world
# Creating ConfigMaps
# Verify
oc get -o yaml configmap/<configmap-name>
# Creating Secrets
# Create ImageStreams
# oc tag syntax
oc tag <original> <destination>
# Example
oc tag quay.io/image-name:tag image-name:tag
# List ImageStreams
oc get is
# List tags
oc get istag
# Creating services
# Creating Routes
# General Syntax
oc scale dc/<dc name> --replicas=<desired replicas>
# Autoscaling
# Example of scaling Hello World between 1 and 10 pods with an 80% CPU target
oc autoscale dc/hello-world \
--min 1 \
--max 10 \
--cpu-percent=80
# Main syntax
oc set volume dc/<dc name> --add --type emptyDir --mount-path <path inside
container>
# Main command
oc set volume <DC name> --add --configmap-name <configmap name> --mount-path <path
inside container>
oc new-app hello-world \
-p MESSAGE="Hello from parameter override."
# Process templates
# With parameters
oc process hello-world -o yaml \
-p MESSAGE="Hello from oc process"