Kubectl Cheatsheet
Searchable reference of 72 essential kubectl commands. Find what you need fast.
72 commands found
Cluster Info
Show cluster info
kubectl cluster-infoList all nodes
kubectl get nodesShow node details
kubectl describe node <node-name>Get cluster component statuses
kubectl get componentstatusesView cluster API resources
kubectl api-resourcesPods
List pods in current namespace
kubectl get podsList pods in all namespaces
kubectl get pods --all-namespacesList pods with wide output
kubectl get pods -o wideDescribe a pod
kubectl describe pod <pod-name>Delete a pod
kubectl delete pod <pod-name>Get pod YAML definition
kubectl get pod <pod-name> -o yamlRun a temporary debug pod
kubectl run debug --image=busybox --rm -it -- shExecute command in a pod
kubectl exec -it <pod-name> -- /bin/shWatch pod status changes
kubectl get pods -wDeployments
List deployments
kubectl get deploymentsCreate deployment from image
kubectl create deployment <name> --image=<image>Delete a deployment
kubectl delete deployment <name>Edit a deployment
kubectl edit deployment <name>Set deployment image
kubectl set image deployment/<name> <container>=<image>Describe a deployment
kubectl describe deployment <name>Services
List services
kubectl get servicesExpose deployment as service
kubectl expose deployment <name> --port=80 --type=LoadBalancerDelete a service
kubectl delete service <name>Get service endpoints
kubectl get endpoints <service-name>Describe a service
kubectl describe service <name>ConfigMaps & Secrets
List configmaps
kubectl get configmapsCreate configmap from file
kubectl create configmap <name> --from-file=<path>Create configmap from literal
kubectl create configmap <name> --from-literal=key=valueList secrets
kubectl get secretsCreate secret from literal
kubectl create secret generic <name> --from-literal=key=valueDecode a secret value
kubectl get secret <name> -o jsonpath='{.data.key}' | base64 -dNamespaces
List namespaces
kubectl get namespacesCreate a namespace
kubectl create namespace <name>Delete a namespace
kubectl delete namespace <name>Set default namespace
kubectl config set-context --current --namespace=<name>Get resources in a namespace
kubectl get all -n <namespace>Logs & Debugging
View pod logs
kubectl logs <pod-name>Stream pod logs
kubectl logs -f <pod-name>View previous container logs
kubectl logs <pod-name> --previousView logs for specific container
kubectl logs <pod-name> -c <container-name>Get events in namespace
kubectl get events --sort-by=.metadata.creationTimestampTop pods by resource usage
kubectl top podsTop nodes by resource usage
kubectl top nodesPort forward to a pod
kubectl port-forward <pod-name> 8080:80Scaling
Scale deployment replicas
kubectl scale deployment <name> --replicas=3Autoscale deployment
kubectl autoscale deployment <name> --min=2 --max=10 --cpu-percent=80Get horizontal pod autoscalers
kubectl get hpaDelete horizontal pod autoscaler
kubectl delete hpa <name>Rollouts
Check rollout status
kubectl rollout status deployment/<name>View rollout history
kubectl rollout history deployment/<name>Undo last rollout
kubectl rollout undo deployment/<name>Rollback to specific revision
kubectl rollout undo deployment/<name> --to-revision=2Pause a rollout
kubectl rollout pause deployment/<name>Resume a rollout
kubectl rollout resume deployment/<name>Restart deployment (rolling)
kubectl rollout restart deployment/<name>Networking
List ingresses
kubectl get ingressDescribe an ingress
kubectl describe ingress <name>List network policies
kubectl get networkpoliciesTest DNS resolution from pod
kubectl exec -it <pod> -- nslookup <service>Get all endpoints
kubectl get endpointsRBAC
List cluster roles
kubectl get clusterrolesList role bindings
kubectl get rolebindingsList cluster role bindings
kubectl get clusterrolebindingsCheck API access
kubectl auth can-i create podsCheck access as another user
kubectl auth can-i get pods --as=system:serviceaccount:ns:saCreate service account
kubectl create serviceaccount <name>Nodes
Cordon a node (prevent scheduling)
kubectl cordon <node-name>Uncordon a node
kubectl uncordon <node-name>Drain a node for maintenance
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-dataTaint a node
kubectl taint nodes <node> key=value:NoScheduleRemove taint from a node
kubectl taint nodes <node> key=value:NoSchedule-Label a node
kubectl label nodes <node-name> disktype=ssdWhat is kubectl?
kubectl is the official command-line interface (CLI) for interacting with Kubernetes clusters. It communicates with the Kubernetes API server to create, inspect, update, and delete resources like pods, deployments, services, and config maps. Whether you are managing a local minikube cluster or a production EKS/GKE/AKS environment, kubectl is the primary tool for day-to-day Kubernetes operations and is essential knowledge for any DevOps engineer or platform team member.
This kubectl cheatsheet organizes the most frequently used commands by workflow: viewing cluster state, deploying applications, debugging issues, managing configurations, and handling networking. DevOps engineers use kubectl dozens of times daily for checking pod health, tailing logs, rolling out deployments, scaling services, executing into containers for debugging, and applying infrastructure changes. Having these commands readily accessible saves significant time during incident response and routine operations.
Frequently Asked Questions
How to delete a pod in Kubernetes?
Use kubectl delete pod pod-name -n namespace to delete a specific pod. If the pod is managed by a deployment (most common case), Kubernetes will automatically create a replacement pod. To force-delete a stuck pod, add --grace-period=0 --force. To delete all pods in a namespace, use kubectl delete pods --all -n namespace, but be careful—this affects all running workloads.
How to get logs from a pod?
Use kubectl logs pod-name to view logs from the main container. Add -f for real-time streaming (like tail -f), --previous to see logs from the last crashed container, -c container-name for multi-container pods, and --since=1h to filter by time. For aggregating logs across multiple pods, use kubectl logs -l app=myapp to query by label selector.
How to scale a deployment with kubectl?
Use kubectl scale deployment deployment-name --replicas=5 to change the number of pod replicas. You can also use kubectl autoscale deployment deployment-name --min=2 --max=10 --cpu-percent=80 to create a Horizontal Pod Autoscaler. To check current scale, use kubectl get deployment deployment-name and look at the READY column showing current/desired replicas.