Kubernetes (kubectl) Cheatsheet
Production kubectl cheatsheet for CKA prep, cluster administration, Pod debugging, Deployments, Services, RBAC, and Helm.
Cluster Info
10 commandskubectl version --clientbeginnerShow the installed kubectl client version without querying the cluster
kubectl cluster-infobeginnerDisplay the cluster control plane and core service endpoints
kubectl get nodesbeginnerList all nodes and their readiness status in the current cluster
kubectl get nodes -o widebeginnerList nodes with extra details like internal IPs, OS image, and container runtime
kubectl describe node <name>intermediateShow detailed capacity, conditions, labels, taints, and pod allocation for a node
kubectl top nodesintermediateView live CPU and memory usage for nodes from Metrics Server
kubectl config viewintermediatePrint the merged kubeconfig with clusters, users, and contexts
kubectl config current-contextbeginnerShow the currently selected kubeconfig context
kubectl config get-contextsbeginnerList all available kubeconfig contexts and highlight the active one
kubectl config use-context <ctx>beginnerSwitch kubectl to a different cluster and user context
Pods
13 commandskubectl get podsbeginnerList pods in the current namespace with basic readiness and status info
kubectl get pods -AbeginnerList pods across every namespace in the cluster
kubectl get pods -n <ns>beginnerList pods only in a specific namespace
kubectl get pods -o widebeginnerShow pods with extra details like node placement and pod IPs
kubectl describe pod <name>intermediateInspect pod metadata, container states, events, probes, and mounts
kubectl logs <pod>beginnerFetch logs from the main container in a pod
kubectl logs <pod> -fbeginnerStream logs from a pod in real time
kubectl logs <pod> --previousintermediateView logs from the previously terminated container instance in a restarting pod
kubectl exec -it <pod> -- /bin/shintermediateOpen an interactive shell inside a pod using the default container
kubectl exec -it <pod> -c <container> -- bashintermediateOpen a shell inside a specific container in a multi-container pod
kubectl delete pod <name>beginnerDelete a pod and let its controller recreate it if managed
kubectl run nginx --image=nginxbeginnerCreate a quick standalone pod directly from an image
kubectl port-forward pod/<name> 8080:80intermediateForward a local port to a pod port for direct debugging access
Deployments
12 commandskubectl get deploymentsbeginnerList deployments in the current namespace with desired and ready replica counts
kubectl describe deployment <name>intermediateInspect a deployment strategy, pod template, rollout conditions, and events
kubectl create deployment nginx --image=nginxbeginnerCreate a deployment from a single image directly from the CLI
kubectl scale deployment <name> --replicas=3beginnerChange the number of desired pod replicas for a deployment
kubectl set image deployment/<name> <container>=<image>:tagintermediateUpdate a container image and trigger a rolling rollout
kubectl rollout status deployment/<name>intermediateWatch the rollout until the deployment successfully completes or fails
kubectl rollout history deployment/<name>intermediateShow previous rollout revisions for a deployment
kubectl rollout undo deployment/<name>intermediateRoll back the deployment to the previous revision
kubectl rollout undo deployment/<name> --to-revision=2advancedRoll back the deployment to a specific stored revision
kubectl delete deployment <name>beginnerDelete a deployment and its managed ReplicaSets and pods
kubectl apply -f deployment.yamlbeginnerCreate or update a deployment declaratively from a manifest file
kubectl edit deployment <name>advancedOpen the live deployment manifest in your editor for an immediate change
Services & Networking
11 commandskubectl get svcbeginnerList services in the current namespace with type and cluster IP
kubectl get svc -AbeginnerList services across all namespaces
kubectl describe svc <name>intermediateInspect service ports, selectors, endpoints, and load balancer details
kubectl expose deployment <name> --port=80 --type=ClusterIPbeginnerExpose a deployment internally within the cluster using a ClusterIP service
kubectl expose deployment <name> --port=80 --type=LoadBalancerintermediateExpose a deployment externally through a cloud load balancer
kubectl expose deployment <name> --port=80 --type=NodePortintermediateExpose a deployment on a static port on each cluster node
kubectl get ingressbeginnerList ingress resources and their configured hosts and addresses
kubectl describe ingress <name>intermediateInspect ingress rules, TLS configuration, and backend service routing
kubectl get endpointsintermediateShow which pod IPs are currently backing each service
kubectl port-forward svc/<name> 8080:80intermediateForward a local port to a service for testing without external exposure
kubectl delete svc <name>beginnerDelete a service resource by name
Namespaces
8 commandskubectl get namespacesbeginnerList all namespaces in the cluster
kubectl create namespace <name>beginnerCreate a new namespace for an application, team, or environment
kubectl delete namespace <name>intermediateDelete a namespace and everything contained inside it
kubectl get all -n <namespace>beginnerList the main workload and service resources in a target namespace
kubectl config set-context --current --namespace=<name>intermediateSet the default namespace for the current context to reduce repeated -n flags
kubectl get pods --all-namespacesbeginnerList pods across every namespace using the long-form namespace flag
kubectl get quota -n <namespace>intermediateView resource quota usage and hard limits for a namespace
kubectl describe namespace <name>intermediateInspect a namespace including labels, annotations, quotas, and limit ranges
ConfigMaps & Secrets
9 commandskubectl get configmapsbeginnerList ConfigMaps in the current namespace
kubectl describe configmap <name>intermediateShow the keys and metadata stored in a ConfigMap
kubectl create configmap my-config --from-literal=key=valuebeginnerCreate a ConfigMap from one or more literal key-value pairs
kubectl create configmap my-config --from-file=config.envintermediateCreate a ConfigMap from a local file such as an env file or config artifact
kubectl get secretsbeginnerList secrets in the current namespace
kubectl describe secret <name>intermediateInspect secret metadata and available keys without printing decoded values
kubectl create secret generic my-secret --from-literal=password=abcbeginnerCreate a generic secret from literal key-value pairs
kubectl create secret docker-registry regcred --docker-server=... --docker-username=... --docker-password=...advancedCreate an image pull secret for a private container registry
kubectl get secret <name> -o jsonpath='{.data.key}' | base64 -dadvancedDecode a specific secret key value from base64 for troubleshooting
Storage
8 commandskubectl get pvbeginnerList cluster-wide persistent volumes and their binding state
kubectl get pvcbeginnerList persistent volume claims in the current namespace
kubectl get pvc -n <namespace>beginnerList persistent volume claims in a specific namespace
kubectl describe pv <name>intermediateInspect a persistent volume including reclaim policy, capacity, and claim binding
kubectl describe pvc <name>intermediateInspect a claim including requested size, access modes, and mounted workloads
kubectl delete pvc <name>intermediateDelete a persistent volume claim and release its bound volume according to policy
kubectl get storageclassbeginnerList available storage classes and identify the default provisioner
kubectl describe storageclass <name>intermediateInspect provisioner parameters, reclaim policy, and binding mode for a storage class
Troubleshooting
12 commandskubectl get events --sort-by=.metadata.creationTimestampintermediateList cluster events in chronological order to surface the newest failures last
kubectl get events -n <ns> --field-selector=reason=FailedintermediateFilter namespace events down to failure-related entries only
kubectl describe pod <name> | grep -A 10 EventsadvancedExtract the events section from a pod description for quick CLI triage
kubectl logs <pod> --since=1hintermediateShow logs generated within the last hour to narrow noisy output
kubectl logs <pod> --tail=100beginnerShow only the most recent log lines from a pod
kubectl top podsintermediateView CPU and memory usage for pods in the current namespace
kubectl top pods -n <namespace>intermediateView CPU and memory usage for pods in a specific namespace
kubectl get pods --field-selector=status.phase=PendingintermediateList only pods that are still waiting to schedule or start
kubectl get pods --field-selector=status.phase=FailedintermediateList pods whose last phase is Failed for cleanup or investigation
kubectl drain <node> --ignore-daemonsetsadvancedSafely evict workloads from a node before maintenance or termination
kubectl cordon <node>advancedMark a node unschedulable so new pods are not placed on it
kubectl uncordon <node>advancedMark a node schedulable again after maintenance is complete