Get all pods across namespaces
Lists all pods across all namespaces in the cluster.
kubectl get pods --all-namespaces
29 commands from the cloud runbook. Fill in a placeholder once and every command uses it.
Lists all pods across all namespaces in the cluster.
kubectl get pods --all-namespaces
Get recent events in a namespace sorted by their creation time.
kubectl get events --sort-by='.metadata.creationTimestamp'
Displays CPU and Memory usage for all nodes.
kubectl top nodes
Bypasses graceful termination to kill a pod.
Caution. Removes the pod from the API without waiting for the kubelet to confirm it stopped. A StatefulSet pod can end up running twice against the same volume. Try a normal delete first.
kubectl delete pod <pod-name> --grace-period=0 --force
Forwards local port to a service port.
kubectl port-forward svc/<service-name> 8080:80
Fetches and decodes a base64 Kubernetes secret.
kubectl get secret <secret-name> -o jsonpath='{.data.<key>}' | base64 --decode
Prints the secret in plain text to your terminal and its scrollback.
Useful for checking why a pod crashed before it restarted.
kubectl logs <pod-name> --previous
Check if your current user has permission to perform an action.
kubectl auth can-i create deployments --namespace dev
Generates the YAML for a resource without actually creating it.
kubectl create deployment nginx --image=nginx --dry-run=client -o yaml > nginx.yaml
Cordons the node and evicts its pods before maintenance, respecting PodDisruptionBudgets.
Caution. --delete-emptydir-data deletes the data in emptyDir volumes on that node.
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data
Opens an interactive shell session inside a running pod.
kubectl exec -it <pod-name> -- /bin/sh
Triggers a rolling restart of all pods in a deployment.
kubectl rollout restart deployment/<deployment-name>
Sets the replica count of a deployment.
kubectl scale deployment/<deployment-name> --replicas=5
If a HorizontalPodAutoscaler manages the deployment, it will change the count back.
Updates the container image of a deployment without editing YAML.
kubectl set image deployment/<deployment-name> <container-name>=<image-name>:<tag>
Shows the documentation and fields for a specific Kubernetes resource.
kubectl explain pod.spec.containers
Checks the revision history of a deployment.
kubectl rollout history deployment/<deployment-name>
Exports the live YAML configuration of a running pod.
kubectl get pod <pod-name> -o yaml
Updates a field on a resource without an editor.
kubectl patch deployment <deployment-name> -p '{"spec": {"replicas": 3}}'
Adds or updates a label on a Kubernetes node for scheduling.
kubectl label node <node-name> env=production
Adds a taint to a node to repel pods that don't tolerate it.
kubectl taint nodes <node-name> key=value:NoSchedule
Creates a ConfigMap from a local file.
kubectl create configmap my-config --from-file=config.properties
Rolls back a deployment to the previous revision.
kubectl rollout undo deployment/<deployment-name>
Shows all available contexts in your kubeconfig.
kubectl config get-contexts
Changes the active Kubernetes context.
kubectl config use-context <context-name>
Shows CPU and memory usage of pods sorted by CPU.
kubectl top pods --sort-by=cpu --all-namespaces
Lists pods where a container last terminated with OOMKilled.
kubectl get pods -A -o jsonpath='{range .items[*]}{.metadata.namespace}{"/"}{.metadata.name}{" "}{.status.containerStatuses[*].lastState.terminated.reason}{"\n"}{end}' | grep OOMKilled
Shows a pod's status, container states, restart reasons and recent events.
kubectl describe pod <pod-name> -n <namespace>
Waits for a deployment rollout and exits non-zero if it fails.
kubectl rollout status deployment/<deployment-name> -n <namespace>
Marks a node unschedulable; running pods stay where they are.
kubectl cordon <node-name>