Searchable kubectl commands cheat sheet organized by category. Covers basics, Pod operations, deployments, namespaces, and debugging with one-click copy.
Enter a command name in the search field, or filter by category (Basic, Pod, Deploy, etc.) to find the command you need.
Check the command description, common options, and practical usage examples.
Click on an example command to copy it to your clipboard for immediate use in your terminal.
kubectl get podsList all pods in current namespacekubectl get pods -o wideList pods with node and IP infokubectl get all -n my-namespaceList all resources in a namespacekubectl describe pod my-podDescribe a specific podkubectl describe deployment my-deployDescribe a deploymentkubectl describe node my-nodeDescribe a nodekubectl create -f pod.yamlCreate resource from filekubectl create deployment my-app --image=nginxCreate a deployment imperativelykubectl create secret generic my-secret --from-literal=key=valueCreate a secretkubectl delete pod my-podDelete a specific podkubectl delete -f deployment.yamlDelete resources defined in filekubectl delete pods -l app=my-appDelete pods by labelkubectl apply -f deployment.yamlApply configuration from filekubectl apply -f ./manifests/Apply all files in directorykubectl apply -f https://example.com/manifest.yamlApply from URLkubectl edit deployment my-deployEdit a deploymentkubectl edit configmap my-configEdit a ConfigMapkubectl edit svc my-serviceEdit a servicekubectl logs my-podPrint logs of a podkubectl logs my-pod --tail=100Show last 100 log lineskubectl logs my-pod -c my-containerLogs from specific containerkubectl exec -it my-pod -- /bin/bashOpen interactive shell in podkubectl exec my-pod -- ls /appRun a command in podkubectl exec -it my-pod -c sidecar -- shShell into specific containerkubectl port-forward pod/my-pod 8080:80Forward local 8080 to pod port 80kubectl port-forward svc/my-svc 8080:80Forward to service portkubectl port-forward deployment/my-deploy 8080:80Forward to deployment portkubectl cp my-pod:/app/logs ./logsCopy from pod to localkubectl cp ./config.yaml my-pod:/app/config.yamlCopy from local to podkubectl cp my-pod:/app/logs ./logs -c my-containerCopy from specific containerkubectl attach my-pod -itAttach to running pod interactivelykubectl attach my-pod -c my-containerAttach to specific containerkubectl top podShow CPU/memory usage of podskubectl top pod --all-namespacesShow usage across all namespaceskubectl top pod --containersShow per-container resource usagekubectl rollout status deployment/my-deployCheck rollout statuskubectl rollout status deployment/my-deploy -wWatch rollout until donekubectl rollout history deployment/my-deployList rollout historykubectl rollout history deployment/my-deploy --revision=2Show details of revision 2kubectl rollout undo deployment/my-deployRollback to previous versionkubectl rollout undo deployment/my-deploy --to-revision=2Rollback to specific revisionkubectl scale deployment my-deploy --replicas=3Scale deployment to 3 replicaskubectl scale deployment my-deploy --replicas=0Scale down to zerokubectl scale statefulset my-sts --replicas=5Scale a StatefulSetkubectl autoscale deployment my-deploy --min=2 --max=10 --cpu-percent=80Create HPA for deploymentkubectl get hpaList Horizontal Pod Autoscalerskubectl set image deployment/my-deploy my-container=nginx:1.25Update container imagekubectl set image deployment/my-deploy *=nginx:latestUpdate all containers to latestkubectl get namespaceList all namespaceskubectl get nsList namespaces (short alias)kubectl get ns -o wideList namespaces with detailskubectl create namespace my-namespaceCreate a namespacekubectl create ns stagingCreate namespace with short aliaskubectl config set-context --current --namespace=my-namespaceSet default namespace for current contextkubectl config set-context my-context --namespace=stagingSet namespace for a specific contextkubectl config viewShow full kubeconfigkubectl config view --minifyShow only current context configkubectl config use-context my-clusterSwitch to a contextkubectl config use-context prod-clusterSwitch to production cluster contextkubectl config get-contextsList all available contextskubectl config get-contexts -o nameList context names onlykubectl config current-contextShow currently active contextkubectl logs -f my-podStream logs from a podkubectl logs -f my-pod --tail=50Stream logs from last 50 lineskubectl logs -f -l app=my-appStream logs from pods with labelkubectl get eventsList events in current namespacekubectl get events --sort-by=.lastTimestampList events sorted by timekubectl get events --field-selector involvedObject.name=my-podEvents for a specific podkubectl top nodeShow CPU/memory usage of nodeskubectl top node --sort-by=memoryShow nodes sorted by memory usagekubectl debug -it my-pod --image=busyboxDebug pod with ephemeral containerkubectl debug node/my-node -it --image=ubuntuDebug a nodekubectl debug my-pod --copy-to=debug-pod --image=busyboxCreate a debugging copy of podkubectl run test --image=busybox --rm -it --restart=Never -- shRun a temporary debugging podkubectl run nginx --image=nginxRun nginx podkubectl patch deployment my-deploy -p '{"spec":{"replicas":3}}'Patch deployment replicaskubectl patch node my-node -p '{"spec":{"unschedulable":true}}'Patch node to unschedulablekubectl label pod my-pod env=productionAdd label to a podkubectl label pod my-pod env-Remove label from a podkubectl label pods -l app=my-app version=v2Label all matching podskubectl annotate pod my-pod description='My app pod'Add annotation to a podkubectl annotate deployment my-deploy description-Remove annotation from deploymentkubectl taint node my-node key=value:NoScheduleTaint a node to prevent schedulingkubectl taint node my-node key:NoSchedule-Remove a taint from a nodekubectl drain my-node --ignore-daemonsetsDrain a node for maintenancekubectl drain my-node --ignore-daemonsets --delete-emptydir-dataDrain node including emptyDir podskubectl cordon my-nodePrevent new pods from being scheduledkubectl uncordon my-nodeRe-enable scheduling on the nodekubectl apply --dry-run=client -f deployment.yamlPreview apply changes (client-side)kubectl apply --dry-run=server -f deployment.yamlPreview apply changes (server-side)kubectl diff -f deployment.yamlShow diff against live statekubectl Commands is a cheat sheet compiling frequently used Kubernetes CLI commands. It comprehensively covers commands needed for cluster management, from basic resource operations to Pod debugging, deployment rollouts, and advanced node management. Each command includes descriptions, common options, and practical examples that can be copied with one click.
kubectl create creates a resource and fails if it already exists. kubectl apply creates or updates a resource declaratively, making it idempotent. apply is preferred for managing resources with YAML files.
Use kubectl config use-context to switch contexts. You can list all available contexts with kubectl config get-contexts. Each context typically corresponds to a different cluster or namespace.
kubectl delete removes a specific resource immediately. kubectl drain gracefully evicts all pods from a node (respecting PodDisruptionBudgets) and marks it unschedulable, preparing it for maintenance.
Use kubectl logs my-pod --previous to see logs from the previous (crashed) container instance. kubectl describe pod my-pod shows events and conditions. kubectl debug creates an ephemeral container for deeper inspection.
kubectl exec runs a new process in the container (e.g. a shell). kubectl attach connects to the existing main process of the container, useful for interacting with programs that read stdin.