Kubernetes Cheatsheet
Essential kubectl commands for managing pods, deployments, services, configs, and cluster resources.
Kubernetes is the industry standard for container orchestration. This cheatsheet covers the most common kubectl commands for managing pods, deployments, services, configmaps, secrets, networking, storage, and debugging — grouped by workflow stage.
All commands use kubectl syntax. Replace namespace, pod name, and other identifiers with your own values.
Cluster Info & Context
kubectl cluster-infokubectl config current-contextkubectl config get-contextskubectl config use-context <name>kubectl get nodeskubectl api-resourceskubectl explain <resource>Pod Management
kubectl get podskubectl get pods -o widekubectl describe pod <name>kubectl logs <pod>kubectl logs <pod> -c <container>kubectl logs --tail 100 -f <pod>kubectl exec -it <pod> -- <cmd>kubectl port-forward <pod> <local>:<remote>Deployments & Scaling
kubectl get deploymentskubectl describe deployment <name>kubectl scale deployment <name> --replicas=nkubectl rollout status deployment/<name>kubectl rollout history deployment/<name>kubectl rollout undo deployment/<name>kubectl set image deployment/<name> <container>=<image>kubectl apply -f <file>kubectl delete -f <file>Services & Networking
kubectl get serviceskubectl describe service <name>kubectl get ingressConfigMaps & Secrets
kubectl get configmapskubectl get secretskubectl create configmap <name> --from-literal=<key>=<val>kubectl create configmap <name> --from-file=<path>kubectl create secret generic <name> --from-literal=<key>=<val>Storage & Volumes
kubectl get pvkubectl get pvckubectl describe pvc <name>Debugging & Logs
kubectl get events --sort-by=.lastTimestampkubectl top podkubectl top nodeKubernetes Cheatsheet
Essential kubectl commands for managing pods, deployments, services, configs, and cluster resources.
Kubernetes is the industry standard for container orchestration. This cheatsheet covers the most common kubectl commands for managing pods, deployments, services, configmaps, secrets, networking, storage, and debugging — grouped by workflow stage.
All commands use kubectl syntax. Replace namespace, pod name, and other identifiers with your own values.
Cluster Info & Context
kubectl cluster-info — Display cluster information — API server, DNS, and core services endpoints.kubectl config current-context — Show the currently active cluster context.kubectl config get-contexts — List all available cluster contexts.kubectl config use-context <name> — Switch to a different cluster context.kubectl get nodes — List all nodes in the cluster with their status.kubectl api-resources — List all available API resource types and their short names.kubectl explain <resource> — Get documentation for a resource type and its fields.Pod Management
kubectl get pods — List all pods in the current namespace.kubectl get pods -o wide — List pods with detailed info: node, IP, and status.kubectl describe pod <name> — Show detailed pod metadata, events, and container status.kubectl logs <pod> — View logs from a pod's primary container.kubectl logs <pod> -c <container> — View logs from a specific container in a multi-container pod.kubectl logs --tail 100 -f <pod> — Tail the last 100 log lines and follow new output.kubectl exec -it <pod> -- <cmd> — Run a command in a pod interactively (e.g. sh).kubectl port-forward <pod> <local>:<remote> — Forward a local port to a port on a pod.Deployments & Scaling
kubectl get deployments — List all deployments in the current namespace.kubectl describe deployment <name> — Show detailed deployment status, strategy, and rollout history.kubectl scale deployment <name> --replicas=n — Scale a deployment to a specific number of replicas.kubectl rollout status deployment/<name> — Watch the status of a rolling update until it completes.kubectl rollout history deployment/<name> — Show the rollout history for a deployment.kubectl rollout undo deployment/<name> — Roll back to the previous deployment revision.kubectl set image deployment/<name> <container>=<image> — Update the container image of a deployment to trigger a rollout.kubectl apply -f <file> — Apply a configuration from a file (create or update resources).kubectl delete -f <file> — Delete resources defined in a file.Services & Networking
kubectl get services — List all services in the current namespace.kubectl describe service <name> — Show service details: type, cluster IP, endpoints, ports.kubectl get ingress — List all ingress resources with host and routing rules.ConfigMaps & Secrets
kubectl get configmaps — List all ConfigMaps in the current namespace.kubectl get secrets — List all Secrets in the current namespace.kubectl create configmap <name> --from-literal=<key>=<val> — Create a ConfigMap from literal key-value pairs.kubectl create configmap <name> --from-file=<path> — Create a ConfigMap from a file (key = filename, value = content).kubectl create secret generic <name> --from-literal=<key>=<val> — Create a generic Secret from literal values.Storage & Volumes
kubectl get pv — List all PersistentVolumes across the cluster.kubectl get pvc — List all PersistentVolumeClaims in the current namespace.kubectl describe pvc <name> — Show PVC details: requested storage, access mode, bound volume.Debugging & Logs
kubectl get events --sort-by=.lastTimestamp — Show recent cluster events sorted by time — useful for diagnosing failures.kubectl top pod — Show CPU and memory usage for pods (requires metrics server).kubectl top node — Show CPU and memory usage for nodes.