Kubernetes (kubectl) Cheatsheet
Quick reference for kubectl commands covering pods, deployments, services, ConfigMaps, namespaces, nodes, debugging, and context switching
67 commands
kubectl get podsList all pods
kubectl get podskubectl get pods -AList pods in all namespaces
kubectl get pods -Akubectl get pods -o wideList pods with extended info
kubectl get pods -o widekubectl get pods -wWatch pods in real-time
kubectl get pods -wkubectl describe podShow detailed pod information
kubectl describe pod my-podkubectl runCreate and run a pod
kubectl run nginx --image=nginx --port=80kubectl delete podDelete a pod
kubectl delete pod my-podkubectl delete pod --forceForce delete a pod
kubectl delete pod my-pod --force --grace-period=0kubectl get pods -lFilter pods by label
kubectl get pods -l app=nginxkubectl get pod -o yamlShow pod YAML definition
kubectl get pod my-pod -o yamlkubectl get deploymentsList all deployments
kubectl get deploymentskubectl create deploymentCreate a deployment
kubectl create deployment nginx --image=nginx --replicas=3kubectl apply -fApply a manifest file
kubectl apply -f deployment.yamlkubectl delete -fDelete resources defined in manifest
kubectl delete -f deployment.yamlkubectl scaleScale deployment replicas
kubectl scale deployment nginx --replicas=5kubectl rollout statusCheck rollout status
kubectl rollout status deployment/nginxkubectl rollout historyShow rollout history
kubectl rollout history deployment/nginxkubectl rollout undoRollback a deployment
kubectl rollout undo deployment/nginxkubectl rollout restartRestart a deployment
kubectl rollout restart deployment/nginxkubectl set imageUpdate container image
kubectl set image deployment/nginx nginx=nginx:1.25kubectl autoscaleSet up Horizontal Pod Autoscaler
kubectl autoscale deployment nginx --min=2 --max=10 --cpu-percent=80kubectl get svcList all services
kubectl get svckubectl exposeExpose resource as a service
kubectl expose deployment nginx --port=80 --type=LoadBalancerkubectl get ingressList all ingresses
kubectl get ingresskubectl describe svcShow detailed service info
kubectl describe svc my-servicekubectl delete svcDelete a service
kubectl delete svc my-servicekubectl get endpointsList endpoints
kubectl get endpoints my-servicekubectl port-forward svcPort-forward to a service
kubectl port-forward svc/my-service 8080:80kubectl get configmapsList ConfigMaps
kubectl get configmapskubectl create configmapCreate a ConfigMap
kubectl create configmap my-config --from-file=config.propertieskubectl get secretsList secrets
kubectl get secretskubectl create secret genericCreate a generic secret
kubectl create secret generic my-secret --from-literal=password=mysecretkubectl create secret tlsCreate a TLS secret
kubectl create secret tls my-tls --cert=cert.pem --key=key.pemkubectl describe configmapDescribe a ConfigMap
kubectl describe configmap my-configkubectl get secret -o jsonpathDecode and display secret value
kubectl get secret my-secret -o jsonpath='{.data.password}' | base64 -dkubectl edit configmapEdit a ConfigMap
kubectl edit configmap my-configkubectl get namespacesList all namespaces
kubectl get namespaceskubectl create namespaceCreate a namespace
kubectl create namespace stagingkubectl delete namespaceDelete a namespace
kubectl delete namespace stagingkubectl config set-context --namespaceSet default namespace
kubectl config set-context --current --namespace=stagingkubectl get all -nList all resources in namespace
kubectl get all -n kube-systemkubectl apply -nApply manifest in namespace
kubectl apply -f app.yaml -n productionkubectl get nodesList all nodes
kubectl get nodeskubectl describe nodeShow detailed node info
kubectl describe node worker-1kubectl top nodesShow node resource usage
kubectl top nodeskubectl top podsShow pod resource usage
kubectl top pods --sort-by=memorykubectl cordonMark node as unschedulable
kubectl cordon worker-1kubectl uncordonMark node as schedulable
kubectl uncordon worker-1kubectl drainDrain node for maintenance
kubectl drain worker-1 --ignore-daemonsets --delete-emptydir-datakubectl taint nodesAdd taint to node
kubectl taint nodes worker-1 key=value:NoSchedulekubectl logsView pod logs
kubectl logs my-podkubectl logs -fStream pod logs in real-time
kubectl logs -f my-podkubectl logs --previousView previous container logs
kubectl logs my-pod --previouskubectl logs -cView specific container logs
kubectl logs my-pod -c sidecarkubectl exec -itExecute interactive command in pod
kubectl exec -it my-pod -- /bin/bashkubectl port-forwardPort-forward to a pod
kubectl port-forward my-pod 8080:80kubectl get eventsList cluster events
kubectl get events --sort-by='.lastTimestamp'kubectl debugAdd ephemeral debug container
kubectl debug my-pod -it --image=busyboxkubectl explainExplain resource fields
kubectl explain pod.spec.containerskubectl api-resourcesList available API resources
kubectl api-resourceskubectl config get-contextsList available contexts
kubectl config get-contextskubectl config current-contextShow current context
kubectl config current-contextkubectl config use-contextSwitch context
kubectl config use-context productionkubectl config set-contextSet a context
kubectl config set-context my-ctx --cluster=my-cluster --user=adminkubectl cluster-infoDisplay cluster info
kubectl cluster-infokubectl config viewView kubeconfig
kubectl config view --minifykubectl versionShow client and server version
kubectl version --short