OpenShift Cheat Sheet

OpenShift is a container orchestration platform that extends Kubernetes. Below is a cheat sheet for common OpenShift commands:

Login and Project

Login to OpenShift Cluster:

oc login <cluster-url>

Switch Project:

oc project <project-name>

List Projects:

oc projects

Work with Applications

Deploy Application from Git:

oc new-app <git-repo-url>

Expose Service to Create Route:

oc expose svc/<service-name>

Scale Deployment:

oc scale --replicas=<replica-count> dc/<deployment-config-name>

Rollback Deployment:

oc rollout undo dc/<deployment-config-name>

Pods and Containers

List Pods:

oc get pods

View Logs of a Pod:

oc logs <pod-name>

Execute Command in a Container:

oc exec <pod-name> -- <command>

Persistent Storage

Create Persistent Volume (PV):

oc create -f <pv-definition-file.yaml>

Create Persistent Volume Claim (PVC):

oc create -f <pvc-definition-file.yaml>

Secrets and ConfigMaps

Create Secret from Literal:

oc create secret generic <secret-name> --from-literal=key=value

Create ConfigMap from Literal:

oc create configmap <configmap-name> --from-literal=key=value

Networking

Create Ingress Route:

oc create route edge --service=<service-name> --hostname=<hostname>

List Routes:

oc get routes

User and Role Management

Add User to Project:

oc adm policy add-role-to-user <role> <username> -n <project-name>

List Roles in a Project:

oc get rolebindings -n <project-name>

Build and Deployment Configuration

Start a New Build:

oc start-build <build-config-name>

Trigger Deployment:

oc rollout latest dc/<deployment-config-name>

Monitoring and Diagnostics

View Metrics (with Hawkular):

oc get --namespace=<project-name> rc

View Resource Usage of Pods:

oc top pods

Clean-Up

Delete Resource:

oc delete <resource-type> <resource-name>

Delete All Resources in a Project:

oc delete all --all

This cheat sheet provides a quick reference for common OpenShift commands. For more detailed information and options, refer to the official OpenShift documentation.