← All cheatsheets

kubectl Cheatsheet

A practical kubectl cheatsheet: switch contexts and namespaces, inspect resources, read logs, exec into pods, apply manifests, and drive rollouts — copy-ready with editable placeholders. Destructive commands are flagged.

Explain a command

Contexts & namespaces

  • List contexts
    kubectl config get-contexts
  • Switch context (cluster)
    kubectl config use-context
  • Set the default namespace
    kubectl config set-context --current --namespace=
  • List namespaces
    kubectl get namespaces

Inspect resources

  • List pods in a namespace
    kubectl get pods -n
  • List pods across all namespaces
    kubectl get pods --all-namespaces
  • List pods with node/IP (wide)
    kubectl get pods -o wide
  • Dump a resource as YAML
    kubectl get -o yaml
  • Describe a resource (events, state)
    kubectl describe
  • Recent events, newest last
    kubectl get events --sort-by=.lastTimestamp
  • Pod CPU/memory usage
    kubectl top pods -n

Logs & exec

  • Follow a pod’s logs
    kubectl logs -f
  • Logs of one container in a pod
    kubectl logs -c
  • Logs from the previous (crashed) container
    kubectl logs --previous
  • Open a shell in a pod
    kubectl exec -it --
  • Port-forward to a pod/service
    kubectl port-forward :

Apply & manage

  • Apply a manifest
    kubectl apply -f
  • Delete a resourcedestructive
    kubectl delete
  • Scale a deployment
    kubectl scale deployment --replicas=
  • Create a ConfigMap from a .env file
    kubectl create configmap --from-env-file=
  • Create a Secret from literals
    kubectl create secret generic --from-literal==

Rollouts

  • Watch a rollout
    kubectl rollout status deployment/
  • Restart a deployment (rolling)
    kubectl rollout restart deployment/
  • Roll back to the previous revisiondestructive
    kubectl rollout undo deployment/

24 commands. Copy-ready with editable placeholders — everything runs in your browser, nothing is sent to a server.