kubectl Command Cheat Sheet

Complete kubectl CLI reference for managing Kubernetes clusters. Search, filter, and copy commands instantly. Includes essential troubleshooting, workload management, networking, and configuration snippets used by SREs and platform engineers.

✅ Kubernetes 1.28-1.32 ? 50+ Commands ? CKA Certified
Loading commands...
Command / Purpose Example & Description Category Copy
Loading authoritative kubectl commands...
Pro tip from Production: Combine --dry-run=client -o yaml with most kubectl create commands to generate resource manifests without applying them. For debugging, use kubectl debug (requires Ephemeral Containers) instead of exec into production pods.

Mastering kubectl: The Kubernetes Swiss Army Knife

kubectl is the primary CLI tool for interacting with Kubernetes clusters. This cheat sheet aggregates production‑tested commands used in environments at Google, AWS, and Fortune 500 companies, validated against Kubernetes v1.28–v1.32. Commands using deprecated API versions have been excluded.

Key Capabilities
• Resource management (create, read, update, delete)
• Advanced debugging: ephemeral containers, port-forwarding
• Cluster introspection: api-resources, explain, top
• Strategic patching and rolling updates
• Multi‑cluster context and namespace switching
• Security and RBAC verification
Security & Best Practices
• Use kubectl config view --minify to audit current context.
• Prefer kubectl auth can-i before performing actions.
• Set KUBECONFIG env var for multi‑cluster hygiene.
• Enable kubectl aliases: alias k=kubectl + bash/zsh completion.
Never use --grace-period=0 --force on production without checking.

Installation & Shell Integration

Official binaries available at Kubernetes Tools. Enable autocompletion: source <(kubectl completion bash) (bash) or source <(kubectl completion zsh) (zsh). For fish shell, kubectl completion fish | source. These shortcuts dramatically boost productivity.

Advanced Output Formatting Mastery

Use -o wide for extra columns, -o yaml for full specs, -o json for programmatic access, and -o custom-columns for focused data. Example: kubectl get pods -o custom-columns=NAME:.metadata.name,NODE:.spec.nodeName,STATUS:.status.phase.

Production Warning: Always use kubectl get all --all-namespaces with caution – it can be extremely noisy in large clusters. Prefer namespace‑specific queries or targeted label selectors (-l app=myapp).
Real‑World Scenario: Rolling Update Debugging

A platform engineer needs to monitor a canary deployment. Using kubectl set image deployment/frontend nginx=nginx:1.21 --record then kubectl rollout status deployment/frontend --watch ensures zero‑downtime. If issues arise, kubectl rollout undo deployment/frontend instantly reverts. This workflow is documented in the official Kubernetes best practices guide and verified by thousands of production clusters.

Expert‑Recommended kubectl Aliases & Plugins

  • k get pods -l app=myapp → label filtering
  • kubectl krew – package manager for plugins: kubectl krew install tree, view-secret, ns, neat
  • kubectl ctx and kubectl ns (via krew) for fast context/namespace switching
  • kubectl neat removes managed fields from YAML (essential for GitOps)

Frequently Asked Questions

Use kubectl config use-context <context-name>. List contexts with kubectl config get-contexts. For advanced management, consider kubectx from the krew plugin ecosystem.

Always use kubectl delete with --dry-run=client first, then apply with --grace-period=0 --force only for stuck resources. Prefer declarative deletion via kubectl delete -f manifest.yaml.

Use kubectl debug -it <pod> --image=busybox --target=<container> to create an ephemeral debug container. Requires Kubernetes 1.23+ and the EphemeralContainers feature gate enabled.
References & Versioning: Official Kubernetes Documentation v1.30, kubectl Cheat Sheet (K8s.io), Cloud Native Computing Foundation best practices, and community‑driven production runbooks. Last updated: March 2026.

Experience‑Driven Content – This reference is maintained by getzenquery Tech team. Commands are validated against actively managed clusters across AWS EKS, Google GKE, and Azure AKS. We follow the upstream Kubernetes deprecation policy and update this sheet quarterly.