DEV Community

DevOps Start
DevOps Start

Posted on • Originally published at devopsstart.com

Essential kubectl Commands Cheat Sheet

Stop memorizing every flag! I've put together a handy kubectl cheat sheet for managing pods, deployments, and debugging. Originally published on devopsstart.com.

Pod Management

Command Description
kubectl get pods List all pods in current namespace
kubectl get pods -A List pods across all namespaces
kubectl describe pod <name> Show detailed pod information
kubectl delete pod <name> Delete a specific pod
kubectl logs <pod> View pod logs
kubectl logs <pod> -f Stream pod logs
kubectl exec -it <pod> -- sh Open shell in pod

Deployments

Command Description
kubectl get deployments List all deployments
kubectl scale deploy <name> --replicas=3 Scale a deployment
kubectl rollout status deploy/<name> Check rollout status
kubectl rollout undo deploy/<name> Rollback a deployment
kubectl set image deploy/<name> <container>=<image> Update container image

Services and Networking

Command Description
kubectl get svc List all services
kubectl get ingress List all ingress resources
kubectl port-forward svc/<name> 8080:80 Forward local port to service
kubectl get endpoints List service endpoints

Debugging

Command Description
kubectl get events --sort-by=.metadata.creationTimestamp View cluster events
kubectl top pods Show pod resource usage
kubectl top nodes Show node resource usage
kubectl logs <pod> --previous View logs from crashed container
kubectl describe node <name> Check node conditions

Context and Config

Command Description
kubectl config get-contexts List all contexts
kubectl config use-context <name> Switch context
kubectl config current-context Show current context
kubectl get ns List namespaces
kubectl config set-context --current --namespace=<ns> Set default namespace

Top comments (0)