Skip to content

Kubernetes — cheat sheet

A one-page lookup for the kubectl and helm commands used across this course. Grouped by task; the course pages cover the why behind each one — this page is just the what.

Context & namespaces

Task Command
Show current context kubectl config current-context
List contexts kubectl config get-contexts
Switch context kubectl config use-context <name>
Set default namespace for the context kubectl config set-context --current --namespace=<ns>
List namespaces kubectl get namespaces

The debug loop — get → describe → logs → events

Task Command
List resources kubectl get pods (add -o wide for node/IP, -w to watch)
Full object detail + recent events kubectl describe pod <name>
Container stdout/stderr kubectl logs <pod> / kubectl logs -f <pod> (follow)
Logs from a previous crashed container kubectl logs --previous <pod>
Logs from one container in a multi-container Pod kubectl logs <pod> -c <container>
Cluster-wide events, newest last kubectl get events --sort-by=.lastTimestamp
Shell inside a running container kubectl exec -it <pod> -- /bin/sh
Attach a temporary debug container kubectl debug <pod> -it --image=<image>
Live resource usage (needs metrics-server) kubectl top pod / kubectl top node

Applying & editing objects

Task Command
Apply a manifest (create or update) kubectl apply -f <file>.yaml
Apply every manifest in a directory kubectl apply -f <dir>/
Preview a change without sending it kubectl diff -f <file>.yaml
Delete what a manifest declares kubectl delete -f <file>.yaml
Edit an object live kubectl edit <kind>/<name>
Patch one field kubectl patch <kind>/<name> -p '<json-or-yaml-patch>'
Print an object's YAML kubectl get <kind>/<name> -o yaml

Workloads

Task Command
Roll out a new image kubectl set image deployment/<name> <container>=<image>:<tag>
Watch a rollout kubectl rollout status deployment/<name>
Roll back to the previous revision kubectl rollout undo deployment/<name>
Rollout history kubectl rollout history deployment/<name>
Scale replicas kubectl scale deployment/<name> --replicas=<n>
Run a one-off Job now, from a CronJob kubectl create job --from=cronjob/<name> <job-name>

Networking

Task Command
List Services kubectl get svc
List Endpoints behind a Service kubectl get endpoints <svc>
List Ingresses kubectl get ingress
Forward a local port to a Pod/Service kubectl port-forward svc/<name> <local>:<remote>
Quick DNS/connectivity probe from inside the cluster kubectl run tmp --rm -it --image=busybox -- sh

Storage

Task Command
List PersistentVolumeClaims kubectl get pvc
List PersistentVolumes kubectl get pv
List StorageClasses kubectl get storageclass
Inspect a PVC's bound PV and status kubectl describe pvc <name>

Config & Secrets

Task Command
Create a ConfigMap from literals kubectl create configmap <name> --from-literal=KEY=value
Create a Secret from literals kubectl create secret generic <name> --from-literal=KEY=value
View a Secret's decoded value kubectl get secret <name> -o jsonpath='{.data.KEY}' \| base64 -d

RBAC

Task Command
Check if you (or a ServiceAccount) can do something kubectl auth can-i <verb> <resource>
Check as another ServiceAccount kubectl auth can-i <verb> <resource> --as=system:serviceaccount:<ns>:<sa>
List Roles / ClusterRoles kubectl get roles / kubectl get clusterroles
List RoleBindings / ClusterRoleBindings kubectl get rolebindings / kubectl get clusterrolebindings

Helm essentials

Task Command
Add and refresh a chart repo helm repo add <name> <url> / helm repo update
Search a repo for a chart helm search repo <keyword>
Install a release helm install <release> <chart> -f values.yaml
Preview rendered manifests without installing helm template <release> <chart> -f values.yaml
Upgrade, or install if absent helm upgrade --install <release> <chart> -f values.yaml
List installed releases helm list
Release history / roll back helm history <release> / helm rollback <release> <revision>
Show the values a chart accepts helm show values <chart>
Uninstall a release helm uninstall <release>

How this connects

The observability & debugging page covers the reasoning behind the get → describe → logs → events loop, the networking page covers the Service/Ingress request path, and the security & RBAC page covers the subject → binding → role model behind auth can-i.