Skip to content

// cheat sheets / kubectl

kubectl quick reference

Essential commands for inspecting, deploying, and debugging applications in your cluster.

CommandsIntermediate#kubernetes#kubectl#command-line

1. Cluster Overview

CommandDescription
kubectl get nodesLists the cluster's nodes and whether each is Ready.
kubectl get pods -AShow all pods across all namespaces.
kubectl get svc,deploy,stsList services, deployments, and stateful sets.
kubectl cluster-infoShows the addresses of the control plane and core cluster services.

2. Inspecting Resources

CommandPurpose
kubectl get <resource>/<name> -o yamlGet detailed YAML output for a specific resource.
kubectl describe pod <pod-name>Show detailed status, events, and conditions for a pod.
kubectl describe deploy <deploy-name>Get details about a deployment, including replica status and events.
kubectl get events --sort-by='.lastTimestamp'List recent cluster events, useful for debugging.

3. Pod Interaction

CommandAction
kubectl logs <pod-name> -fStream logs from a pod. Add -c <container> for multi-container pods.
kubectl exec -it <pod-name> -- bashOpens a shell inside a running pod (use sh if the image has no bash).
kubectl port-forward <pod-name> 8080:80Forward local port 8080 to pod's port 80.
kubectl cp <pod-name>:/app/file .Copy a file from a pod to your local machine.

4. Deploying & Updating

CommandEffect
kubectl apply -f <file.yaml>Apply configuration from a file. Creates or updates resources.
kubectl create -f <file.yaml>Create resources from a file. Fails if resource already exists.
kubectl rollout status deploy/<name>Monitor the status of a deployment rollout.
kubectl rollout undo deploy/<name>Rollback a deployment to the previous revision.

5. Debugging & Troubleshooting

CommandUse Case
kubectl debug -it <resource>/<name> --image=busybox --target=<container>Create an ephemeral container for debugging. Requires Kubernetes 1.23+.
kubectl top pod <pod-name>Show CPU/memory usage for a pod. Requires Metrics Server.
kubectl get pod <pod-name> -o jsonpath='{.status.containerStatuses[*].state}'Quickly check container states within a pod.
kubectl get pod <pod-name> -o wideSee node, IP, and restart count for a pod.

6. Resource Management

CommandAction
kubectl delete -f <file.yaml>Delete resources defined in a file. Use with caution.
kubectl delete pod <pod-name> --force --grace-period=0Force delete a stuck pod immediately. Use with extreme caution.
kubectl scale deploy/<name> --replicas=3Scale a deployment to a specific number of replicas.
kubectl edit deploy/<name>Open resource definition in editor for live changes.

7. Context & Configuration

CommandFunction
kubectl config get-contextsList all available kubectl contexts.
kubectl config use-context <context-name>Switch to a different Kubernetes context.
kubectl config current-contextDisplay the name of the current context.
kubectl config view --minifyShow the active kubeconfig configuration.
archhyarchhy.com/cheat-sheets/kubectlMake your own at archhy.com

Draw your own, with real cloud icons.

Start drawing, free

No account needed to start.