Kubernetes
kubectl Commands Cheat Sheet
Practical kubectl commands for managing Kubernetes clusters, pods, deployments, services and troubleshooting.
What is kubectl?
kubectl is the command-line tool used to communicate with a Kubernetes cluster. It allows you to create, inspect, update and delete Kubernetes resources.
kubectl [command] [TYPE] [NAME] [flags]1. Check Kubernetes Cluster
kubectl cluster-infoDisplays information about the Kubernetes control plane and cluster services.
2. Get Nodes
kubectl get nodesLists all nodes in the current Kubernetes cluster.
kubectl get nodes NAME STATUS ROLES AGE worker01 Ready <none> 10d
3. Get Pods
kubectl get podsLists pods in the current namespace.
kubectl get pods -ALists pods across all namespaces.
kubectl get pods -o wideShows additional information such as pod IP and node.
4. Describe a Pod
kubectl describe pod <pod-name>Shows detailed information about a pod, including events, containers, volumes and scheduling information.
Useful when troubleshooting a pod that is not starting.
5. View Pod Logs
kubectl logs <pod-name>Displays logs from a pod's container.
kubectl logs -f <pod-name>Continuously follows the container logs.
6. Execute Commands Inside a Pod
kubectl exec -it <pod-name> -- /bin/bashOpens an interactive shell inside a running container.
Some minimal container images do not include bash. In those cases, try /bin/sh if available.
7. Get Deployments
kubectl get deploymentsLists deployments in the current namespace.
8. Get Services
kubectl get servicesLists Kubernetes Services and their networking information.
kubectl get svc is the shorter form.
9. Apply a Kubernetes Manifest
kubectl apply -f deployment.yamlCreates or updates Kubernetes resources defined in a YAML manifest.
10. Delete a Pod
kubectl delete pod <pod-name>Deletes the specified pod.
If the pod is managed by a Deployment, ReplicaSet or another controller, Kubernetes may create a replacement pod.
Quick Troubleshooting Workflow
kubectl get pods kubectl describe pod <pod-name> kubectl logs <pod-name> kubectl get events kubectl get nodes kubectl get deployments kubectl get services
A common troubleshooting approach is to first check the pod status, inspect its events, review application logs and then check the surrounding Kubernetes resources.
DevOps Commands Tip
When troubleshooting Kubernetes, don't immediately delete the pod. First inspect its status, events and logs. This often reveals the actual problem and preserves useful diagnostic information.