OpenShfit Cheatsheet
OpenShfit Cheatsheet
oc get clusterversion # Version Information of Kubernetes API server and the OpenShift server
oc cluster-info # Check URL of the OpenShift console & URL of the Kubernetes API server
oc cluster-info --loglevel=5 # Display the cluster with a higher log level
kubectl cluster-info dump # Dump current cluster state to stdout
kubectl cluster-info dump --all-namespaces # Dump all namespaces to stdout
kubectl cluster-info dump --output-dir=/path/to/cluster-state # Dump current cluster state to /path/to/cluster-state
kubectl cluster-info dump --namespaces default,kube-system --output-dir=/path/to/cluster-state
# Dump a set of namespaces to /path/to/cluster-state
oc new-app --list # List all local templates and image streams that can be used to create an app
oc new-app . --image=registry/repo/langimage # Create an application based on the source code in the current git repository
oc new-app --strategy=docker --binary --name <app name> # Create an application with Docker based build strategy expecting binary input
oc new-app --search thinknyx # Search all templates, image streams, and images that match "thinknyx"
oc new-app --search --template=thinknyx # Search for "thinknyx", but only in stored templates
oc new-app --search --template=thinknyx --output=yaml # Search for "thinknyx" in stored templates and print the output as YAML
Project Management
Service Management
oc create service clusterip <service name> --tcp=[5678]:[8080] # Creates a new cluster ip service
oc create service externalname <service name> --external-name <name> # Create a new ExternalName service
oc create service nodeport <service nmae> --tcp=[5678]:[8080] # Create a new NodePort service
oc expose service <service name> # Create a route to expose a service externally
oc expose service <service name> -l name=<label name> --name=<route name> # Create a route with label and route name
oc delete service <service name> # Deletes a service
oc get service <service name> # Retrieves information about services
oc get service <service name> -o yaml # Retrieves information about services on YAML format
oc describe service <service name> # Displays detailed information about a service
oc edit service <service name> # Modifies a service
oc port-forward <pod-name> <local-port>:<remote-port> # Forwards traffic from a local port to a port on a running pod
oc scale --replicas=3 rs/<resource name> # Scales a deployment to a specified number of replicas
Storage Management
oc create -f <storageclass>.yaml # Creates a new storage class based on the requirment like glusterfs,
oc create -f <name_of_endpoint_file> # To create the endpoints of static volume provisioning
oc get endpoints # To check the endpoint IP Address and Name
oc delete storageclasses.storage.k8s.io # Deletes a storage class
oc get pv -o wide # Retrieves information about persistent volumes
oc describe pv # Displays detailed information about a persistent volume
oc get pvc -o wide # Retrieves information about persistent volume claims
oc describe pvc # Displays detailed information about a persistent volume claim
Machine Config
oc debug node/<node-name> --image=<debug-image> # Debug pod with a custom debug image on a specific node for troubleshooting
oc debug deployment/<deployment-name> # Debug pod on a specific deployment for troubleshooting
oc debug pod/<pod-name> # Debug pod for a specific pod for troubleshooting
oc debug <resource>/<resource-name> # Debug pod for a specific resource for troubleshooting
oc debug --image=<debug-image> # Debug pod with a custom debug image for troubleshooting
oc debug job/test --as-user=1000000 # Test running a job as a non-root user
oc debug --as-root # Debug pod with root privileges for troubleshooting
oc debug --uid=<user-id> # Debug pod with a specific user ID for troubleshooting
C opyright © Thinknyx Technologies
OpenShift OpenShift Cheatsheet
oc adm policy add-cluster-role-to-user <role> <user> # Add cluster role to a exsisting user
oc adm policy add-role-to-user <role> <user> # Add normal role to a existing user
oc adm policy add-scc-to-user <scc policy> <user1> <user2> # Add scc policy to a existing user
+91 9810344919/9717917973