Kubernetes has become the de facto standard for container orchestration. Whether you are managing a small cluster or a production-grade deployment spanning multiple regions, these 100+ commands will cover everything you need to operate Kubernetes effectively.
1. Cluster Information
kubectl cluster-info — Display cluster information.
kubectl cluster-info dump — Dump cluster state for debugging.
kubectl version — Show client and server versions.
kubectl config view — Show merged kubeconfig settings.
kubectl config get-contexts — List available contexts.
kubectl config current-context — Show current context.
kubectl config use-context my-cluster — Switch to a different context.
kubectl api-resources — List all available API resources.
kubectl api-versions — List API versions available on the cluster.
kubectl get componentstatuses — Check control plane components health.
2. Pod Operations
kubectl get pods — List all pods in the current namespace.
kubectl get pods -A — List pods across all namespaces.
kubectl get pods -o wide — List pods with more details (node, IP).
kubectl describe pod my-pod — Detailed info about a pod.
kubectl logs my-pod — View pod logs.
kubectl logs -f my-pod — Follow pod logs in real time.
kubectl logs my-pod -c my-container — Logs from a specific container.
kubectl exec -it my-pod -- /bin/bash — Open a shell inside a pod.
kubectl port-forward my-pod 8080:80 — Forward local port to pod port.
kubectl cp my-pod:/path/to/file ./local-file — Copy files from/to pods.
kubectl top pod — Show CPU/memory metrics for pods.
kubectl delete pod my-pod — Delete a pod.
3. Deployments
kubectl get deployments — List deployments.
kubectl describe deployment my-deploy — Detailed info.
kubectl create deployment my-deploy --image=nginx — Create a deployment.
kubectl scale deployment my-deploy --replicas=5 — Scale replicas.
kubectl autoscale deployment my-deploy --min=2 --max=10 --cpu-percent=80 — Auto-scale.
kubectl set image deployment/my-deploy nginx=nginx:1.25 — Update image.
kubectl rollout status deployment/my-deploy — Check rollout status.
kubectl rollout history deployment/my-deploy — Show rollout history.
kubectl rollout undo deployment/my-deploy — Rollback to previous version.
kubectl rollout restart deployment/my-deploy — Restart all pods gracefully.
4. Services and Networking
kubectl get services — List services.
kubectl describe service my-service — Service details.
kubectl expose deployment my-deploy --port=80 --type=LoadBalancer — Expose as service.
kubectl get endpoints — List service endpoints.
kubectl get ingress — List ingress resources.
kubectl describe ingress my-ingress — Ingress details.
5. Configuration and Secrets
kubectl get configmaps — List ConfigMaps.
kubectl create configmap my-config --from-file=config.properties — Create from file.
kubectl create configmap my-config --from-literal=key=value — Create from literal.
kubectl get secrets — List secrets.
kubectl create secret generic my-secret --from-literal=password=abc123 — Create secret.
kubectl get secret my-secret -o jsonpath="{.data.password}" | base64 -d — Decode secret.
6. Namespaces
kubectl get namespaces — List namespaces.
kubectl create namespace my-namespace — Create a namespace.
kubectl config set-context --current --namespace=my-namespace — Switch default namespace.
kubectl delete namespace my-namespace — Delete a namespace and all resources.
7. Volumes and Storage
kubectl get pv — List persistent volumes.
kubectl get pvc — List persistent volume claims.
kubectl describe pvc my-claim — PVC details.
kubectl get storageclasses — List storage classes.
8. Nodes and Cluster Administration
kubectl get nodes — List cluster nodes.
kubectl describe node my-node — Node details and resource usage.
kubectl top node — Show CPU/memory usage per node.
kubectl cordon my-node — Mark node as unschedulable.
kubectl uncordon my-node — Mark node as schedulable.
kubectl drain my-node --ignore-daemonsets — Safely evict all pods from a node.
kubectl label node my-node disktype=ssd — Add a label to a node.
9. Debugging and Troubleshooting
kubectl get events --sort-by=.lastTimestamp — List events sorted by time.
kubectl get events -A --watch — Watch events across all namespaces.
kubectl logs --previous my-pod — Logs from previous container instance (after crash).
kubectl debug my-pod --image=ubuntu -- /bin/bash — Debug running pod with ephemeral container.
kubectl run test-pod --image=alpine --rm -it -- /bin/sh — Run temporary debug pod.
kubectl top pod -A --sort-by=cpu — Pods sorted by CPU usage.
10. Daily kubectl Shortcuts
alias k=kubectl — Use k instead of kubectl.
source <(kubectl completion bash) — Enable bash completion.
kubectl explain pod.spec.containers — Docs for any resource field.
kubectl api-resources --verbs=list --namespaced -o name | xargs -n1 kubectl get -A — List ALL resources across all namespaces.
Master these commands and you can manage any Kubernetes cluster with confidence. We publish cheat sheets and references for DevOps tools — check out our full product catalog for guides on Linux, Docker, Git, Python, and more.
For a complete DevOps toolkit covering Docker, Kubernetes, CI/CD, and server automation, see the All-8 Bundle ($69) — 8 premium products at 40% off.
Also see: Our 80+ Essential Docker Commands guide for container basics, and the 100 Essential Linux Commands guide for server administration.