Skip to content

Instantly share code, notes, and snippets.

@lreverchuk
Last active June 13, 2026 10:58
Show Gist options
  • Select an option

  • Save lreverchuk/c10cccd8b3eb3469fa84aed5973392b1 to your computer and use it in GitHub Desktop.

Select an option

Save lreverchuk/c10cccd8b3eb3469fa84aed5973392b1 to your computer and use it in GitHub Desktop.
kubectl Commands Cheatsheet: Kubernetes Day-to-Day Reference

kubectl Commands Cheatsheet: Kubernetes Day-to-Day Reference

The kubectl commands you reach for constantly: inspecting pods, logs, deployments, scaling, port-forwarding, contexts, and debugging a broken cluster. Copy-paste ready.

Contexts & config

kubectl config get-contexts                 # list contexts
kubectl config current-context              # which cluster am I on
kubectl config use-context my-cluster       # switch context
kubectl config set-context --current --namespace=dev   # default namespace

Get & describe resources

kubectl get pods                            # pods in current namespace
kubectl get pods -A                         # all namespaces
kubectl get pods -o wide                    # with node + IP
kubectl get pods -w                         # watch live
kubectl get all                             # pods, services, deployments, etc.
kubectl get deploy,svc,ingress             # multiple types at once
kubectl describe pod my-pod                 # full detail + events
kubectl get events --sort-by=.metadata.creationTimestamp

Logs & exec

kubectl logs my-pod                         # logs
kubectl logs -f my-pod                      # follow
kubectl logs my-pod -c my-container         # specific container
kubectl logs --previous my-pod              # logs from the crashed instance
kubectl exec -it my-pod -- sh               # shell into a pod
kubectl exec my-pod -- env                  # run one command

Apply, edit, delete

kubectl apply -f deploy.yaml                # create/update from manifest
kubectl apply -f ./manifests/               # whole directory
kubectl edit deployment my-app              # edit live (opens $EDITOR)
kubectl delete -f deploy.yaml
kubectl delete pod my-pod                   # delete one pod (it restarts if managed)
kubectl delete pods --all -n dev            # all pods in a namespace

Scaling & rollouts

kubectl scale deployment my-app --replicas=5
kubectl rollout status deployment my-app
kubectl rollout history deployment my-app
kubectl rollout undo deployment my-app          # roll back to previous
kubectl rollout restart deployment my-app       # restart all pods (rolling)

Port-forward & proxy

kubectl port-forward svc/my-svc 8080:80         # localhost:8080 -> service
kubectl port-forward pod/my-pod 5432:5432       # straight to a pod

Resource usage (needs metrics-server)

kubectl top nodes
kubectl top pods -A

Namespaces & secrets

kubectl get ns
kubectl create namespace staging
kubectl create secret generic db --from-literal=password=s3cret
kubectl get secret db -o jsonpath='{.data.password}' | base64 -d

Debugging a broken cluster

kubectl get pods -A | grep -vE 'Running|Completed'   # find unhealthy pods
kubectl describe pod my-pod | grep -A20 Events        # why won't it start
kubectl get pod my-pod -o yaml                        # full spec
kubectl debug -it my-pod --image=busybox --target=app # ephemeral debug container

Quick reference table

Task Command
Watch pods kubectl get pods -w
Follow logs kubectl logs -f <pod>
Shell into pod kubectl exec -it <pod> -- sh
Apply manifest kubectl apply -f file.yaml
Scale kubectl scale deploy <name> --replicas=N
Restart deployment kubectl rollout restart deploy <name>
Roll back kubectl rollout undo deploy <name>
Port-forward kubectl port-forward svc/<svc> 8080:80
Find broken pods kubectl get pods -A | grep -v Running

Maintained by the team at EchoGlobal. Hiring? See our curated lists of Top Kubernetes Developers, Top Docker Developers, and Top DevOps Engineers on GitHub, or hire pre-vetted talent in days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment