Tool cheatsheet
kubectl 1.37 Cheatsheet
Inspect, deploy, debug and scale workloads on a Kubernetes cluster.
Clusters and contexts
- Check the client version — Print the kubectl client version.
- Check the cluster — Show the addresses of the control plane and core services.
- List contexts — Show the clusters and users in your kubeconfig. The current one is starred.
- Show the current context — Print which cluster kubectl is talking to.
- Switch cluster — Make another context the default.
- Set the default namespace — Use a namespace for the current context so you can skip -n.
Viewing resources
- List pods — Show pods in the current namespace.
- List pods in all namespaces — Show pods across the whole cluster.
- List pods with node and IP — Add the node, pod IP and other columns.
- Watch pods change — Keep the list open and print updates.
- List common resources — Show pods, services, deployments and other workloads in the namespace.
- Show a resource as YAML — Print the live definition of a resource.
- Describe a resource — Show its details and recent events. Start here when a pod won't start.
- Show recent events — List events, oldest first.
- Show CPU and memory use — Needs metrics-server installed in the cluster.
- List resource types — Show every resource type the cluster supports.
Creating and changing
- Apply a manifest — Create or update the resources defined in a file.
- Apply a folder of manifests — Create or update everything in a folder.
- Apply a Kustomize directory — Build and apply a folder containing a kustomization.yaml.
- Create a deployment — Create a deployment from an image.
- Expose a deployment as a service — Create a service in front of a deployment.
- Edit a resource in your editor — Open the live definition and apply your changes on save.
- Delete resources from a manifest — Delete everything defined in a file.
- Delete a pod — Delete a pod. A controller usually creates a replacement.
Logs and debugging
- View a pod's logs — Print the logs of a pod. Add -c CONTAINER when the pod runs more than one container.
- Follow logs — Stream logs as they arrive.
- View logs from before a crash — Print the logs of the previous container instance.
- Open a shell in a pod — Run an interactive shell inside a container.
- Forward a local port — Reach a service from your machine at localhost:8080.
- Run a temporary debug pod — Start a pod with a shell, and delete it when you exit.
- Attach a debug container — Add an ephemeral container to a running pod to inspect it.
- Copy a file from a pod — Copy a file out of a container.
Rollouts and scaling
- Scale a deployment — Set the number of replicas.
- Update the image — Change a container's image, which starts a rolling update.
- Watch a rollout — Wait and report until the rollout finishes.
- See rollout history — List the revisions of a deployment.
- Roll back a deployment — Return to the previous revision.
- Restart a deployment — Restart all pods gradually, without changing the spec.
Config and secrets
- Create a ConfigMap from a file — Store a file's contents as configuration.
- Create a secret — Store a value as a Secret. Use a real value and avoid leaving it in shell history.
- Read a secret value — Decode one key of a Secret.
Related cheatsheets
- Ansible 2 cheatsheet — Run ad-hoc commands and playbooks, manage inventories, roles, collections and secrets with Ansible.
- Argo CD 3 cheatsheet — Install Argo CD, define Applications declaratively, and manage sync, diffs, history and rollbacks with the argocd CLI.
- AWS CLI 2 cheatsheet — Configure credentials and manage S3, EC2, Lambda, logs, containers and secrets with the AWS CLI v2.
- Azure CLI 2 cheatsheet — Sign in and manage resource groups, VMs, web apps, storage, Kubernetes, registries and secrets with the az command.
- Bash and Linux 5 cheatsheet — Everyday shell and Linux commands for files, searching text, permissions, processes and servers.
- Claude API cheatsheet — Call Claude from Python, TypeScript or curl: messages, streaming, thinking, tools, structured output, caching, batches and error handling.