OpenShift CLI Cheat Sheet for Admins

Here is a quick-reference CLI cheat sheet organized by operational domain for day-to-day OpenShift Container Platform (OCP) administration and troubleshooting.

1. Cluster & Operator Health Checks

Bash

# Check status of all Core Operators (Look for DEGRADED=True or AVAILABLE=False)
oc get clusteroperators
# Check overall node status and OS versions
oc get nodes -o wide
# Check cluster version status and history
oc get clusterversion
# View cluster-wide active alerts
oc get alerts
# Check cluster event log sorted by timestamp
oc get events -A --sort-by='.metadata.creationTimestamp' | tail -n 30

2. Node & Machine Management

Bash

# Get MachineConfigPool (MCP) status (Check if UPDATING=True or DEGRADED=True)
oc get mcp
# View machine config rendered versions
oc get machineconfig
# Inspect detailed node resource capacity and usage
oc describe node <node-name>
oc adm top nodes
# Cordon and drain a node for maintenance
oc adm cordon <node-name>
oc adm drain <node-name> --ignore-daemonsets --delete-emptydir-data
# Uncordon node after maintenance
oc adm uncordon <node-name>

3. Pod & Workload Troubleshooting

Bash

# Find pods not in Running/Completed state across all namespaces
oc get pods -A --field-selector=status.phase!=Running,status.phase!=Succeeded
# Show top CPU and memory consuming pods
oc adm top pods -A --sort-by=memory
# View logs for a failing pod (current container)
oc logs <pod-name> -n <namespace> -c <container-name>
# View logs for a PREVIOUS crashed container instance (CrashLoopBackOff)
oc logs <pod-name> -n <namespace> -c <container-name> --previous
# Stream logs across all pods matching a label
oc logs -l app=my-app -n <namespace> --all-containers --tail=100 -f
# Get detailed lifecycle events for a stuck/failing pod
oc describe pod <pod-name> -n <namespace>

4. Advanced Live Debugging & Shell Access

Bash

# Launch a debug pod using the exact spec of a failing application pod
oc debug pod/<pod-name> -n <namespace>
# Attach an ephemeral debug container with nettools (nicolaka/netshoot) to a running pod
oc debug pod/<pod-name> -n <namespace> --image=nicolaka/netshoot --target=<container-name> -it
# Spawn a root debug shell on a specific host node
oc debug node/<node-name>
# Inside the debug pod, switch to host filesystem:
# chroot /host
# Execute interactive bash directly inside a running container
oc exec -it <pod-name> -n <namespace> -c <container-name> -- /bin/bash

5. Networking & Ingress Debugging

Bash

# Check DNS Operator and CoreDNS pod status
oc get clusteroperator dns
oc get pods -n openshift-dns -o wide
# Inspect OpenShift Ingress Routers
oc get pods -n openshift-ingress -o wide
oc get routes -A
# Test internal DNS resolution from a temporary pod
oc run dns-test --image=registry.redhat.io/rhel8/support-tools --rm -it -- dig <service-name>.<namespace>.svc.cluster.local
# View dropped NetworkPolicy logs on OVN-Kubernetes host
oc debug node/<node-name> -- chroot /host journalctl -u ovs-vswitchd -f | grep -i "drop"
# Capture host network traffic via host debug shell
oc debug node/<node-name> -- chroot /host nsenter -t $(crictl inspect --output json $(crictl ps --name <container-name> -q) | jq '.info.pid') -n tcpdump -i any -nn

6. Storage & PVC Diagnostics

Bash

# List all PVCs across the cluster that are Pending or Degraded
oc get pvc -A | grep -v Bound
# Inspect StorageClasses and default provisioners
oc get sc
# View VolumeAttachment objects and CSI node status
oc get volumeattachments
oc get csinodes

7. etcd & Control Plane Recovery

Bash

# Check etcd pod status
oc get pods -n openshift-etcd -l app=etcd
# Execute etcdctl health check inside an etcd container
oc exec -n openshift-etcd -c etcd $(oc get pods -n openshift-etcd -l app=etcd -o jsonpath='{.items[0].metadata.name}') -- etcdctl endpoint health --cluster
# View etcd member list
oc exec -n openshift-etcd -c etcd $(oc get pods -n openshift-etcd -l app=etcd -o jsonpath='{.items[0].metadata.name}') -- etcdctl member list -w table

8. Enterprise Diagnostic Data Collection (must-gather)

Bash

# Collect standard OpenShift diagnostic bundle (Saved to ./must-gather.local)
oc adm must-gather
# Run must-gather for a specific operator (e.g., ODF / Storage)
oc adm must-gather --image=registry.redhat.io/odf4/odf-must-gather-rhel8
# Save must-gather output to a specific directory
oc adm must-gather --dest-dir=./cluster-debug-logs

Leave a Reply