Kubernetes Cheatsheet
kubectl commands for pods, deployments, services, config, RBAC, and cluster management.
Cluster & Context
kubectl version --shortClient and server version
kubectl cluster-infoCluster API server and DNS endpoints
kubectl get nodesList all nodes
kubectl get nodes -o wideNodes with IP, OS, kernel info
kubectl config get-contextsList all kubeconfig contexts
kubectl config use-context my-clusterSwitch active context
kubectl config current-contextShow current context name
kubectl config set-context --current --namespace=devSet default namespace for current context
Client and server version
Cluster API server and DNS endpoints
List all nodes
Nodes with IP, OS, kernel info
List all kubeconfig contexts
Switch active context
Show current context name
Set default namespace for current context
Pods
kubectl get podsList pods in default namespace
kubectl get pods -n kube-systemList pods in specific namespace
kubectl get pods -AList pods across all namespaces
kubectl get pods -o widePods with node and IP info
kubectl get pods -l app=nginxFilter pods by label
kubectl describe pod mypodFull pod details, events, conditions
kubectl logs mypodView pod logs
kubectl logs -f mypodFollow logs in real time
kubectl logs mypod -c mycontainerLogs from specific container in pod
kubectl logs mypod --previousLogs from previous (crashed) container
kubectl exec -it mypod -- bashInteractive shell inside pod
kubectl exec mypod -- cat /etc/hostsRun one-off command in pod
kubectl delete pod mypodDelete pod (will be recreated by Deployment)
kubectl delete pod mypod --force --grace-period=0Force delete stuck pod
kubectl get pod mypod -o yamlGet full pod YAML manifest
List pods in default namespace
List pods in specific namespace
List pods across all namespaces
Pods with node and IP info
Filter pods by label
Full pod details, events, conditions
View pod logs
Follow logs in real time
Logs from specific container in pod
Logs from previous (crashed) container
Interactive shell inside pod
Run one-off command in pod
Delete pod (will be recreated by Deployment)
Force delete stuck pod
Get full pod YAML manifest
Deployments
kubectl get deploymentsList all deployments
kubectl create deployment nginx --image=nginx:1.25Create deployment imperatively
kubectl scale deployment nginx --replicas=3Scale deployment to 3 replicas
kubectl set image deployment/nginx nginx=nginx:1.26Update container image (rolling update)
kubectl rollout status deployment/nginxWatch rollout progress
kubectl rollout history deployment/nginxShow rollout revision history
kubectl rollout undo deployment/nginxRollback to previous revision
kubectl rollout undo deployment/nginx --to-revision=2Rollback to specific revision
kubectl rollout pause deployment/nginxPause rollout mid-way
kubectl rollout resume deployment/nginxResume paused rollout
kubectl delete deployment nginxDelete deployment and its pods
List all deployments
Create deployment imperatively
Scale deployment to 3 replicas
Update container image (rolling update)
Watch rollout progress
Show rollout revision history
Rollback to previous revision
Rollback to specific revision
Pause rollout mid-way
Resume paused rollout
Delete deployment and its pods
Services & Networking
kubectl get servicesList all services
kubectl expose deployment nginx --port=80 --type=ClusterIPExpose deployment as ClusterIP service
kubectl expose deployment nginx --port=80 --type=NodePortExpose as NodePort (accessible outside cluster)
kubectl expose deployment nginx --port=80 --type=LoadBalancerExpose via cloud load balancer
kubectl port-forward svc/nginx 8080:80Forward local port 8080 to service port 80
kubectl port-forward pod/mypod 5000:5000Port forward directly to pod
kubectl get ingress -AList all ingress rules
kubectl get endpoints nginxShow which pods a service routes to
List all services
Expose deployment as ClusterIP service
Expose as NodePort (accessible outside cluster)
Expose via cloud load balancer
Forward local port 8080 to service port 80
Port forward directly to pod
List all ingress rules
Show which pods a service routes to
ConfigMaps & Secrets
kubectl get configmapsList all configmaps
kubectl create configmap app-config --from-file=config.envCreate configmap from file
kubectl create configmap app-config --from-literal=DB_HOST=localhostCreate configmap from literal key=value
kubectl describe configmap app-configView configmap contents
kubectl get secretsList all secrets
kubectl create secret generic db-secret --from-literal=password=S3cr3t!Create opaque secret
kubectl create secret docker-registry regcred --docker-server=ghcr.io --docker-username=user --docker-password=TOKENCreate image pull secret
kubectl get secret db-secret -o jsonpath='{.data.password}' | base64 -dDecode and read secret value
List all configmaps
Create configmap from file
Create configmap from literal key=value
View configmap contents
List all secrets
Create opaque secret
Create image pull secret
Decode and read secret value
Namespaces & RBAC
kubectl get namespacesList all namespaces
kubectl create namespace devCreate namespace
kubectl delete namespace devDelete namespace and everything in it
kubectl get serviceaccounts -n devList service accounts in namespace
kubectl get roles,rolebindings -n devList RBAC roles in namespace
kubectl get clusterroles,clusterrolebindingsList cluster-wide RBAC
kubectl auth can-i create pods --as=system:serviceaccount:dev:mysaCheck if service account has permission
List all namespaces
Create namespace
Delete namespace and everything in it
List service accounts in namespace
List RBAC roles in namespace
List cluster-wide RBAC
Check if service account has permission
Apply & Debug
kubectl apply -f manifest.yamlApply/update resource from YAML
kubectl apply -f ./k8s/Apply all YAMLs in directory
kubectl delete -f manifest.yamlDelete resources defined in YAML
kubectl diff -f manifest.yamlPreview changes before applying
kubectl get events -n dev --sort-by=.lastTimestampRecent events, sorted by time
kubectl top nodesNode CPU and memory usage
kubectl top pods -APod CPU and memory usage across all namespaces
kubectl debug pod/mypod --image=busybox --copy-to=debug-podCreate debug copy of pod with tools
kubectl run tmp --image=busybox --rm -it -- shQuick throwaway debug pod
kubectl get all -n devGet all resources in a namespace
Apply/update resource from YAML
Apply all YAMLs in directory
Delete resources defined in YAML
Preview changes before applying
Recent events, sorted by time
Node CPU and memory usage
Pod CPU and memory usage across all namespaces
Create debug copy of pod with tools
Quick throwaway debug pod
Get all resources in a namespace