All cheatsheets

Cheatsheets

kubectl

Common Kubernetes commands for pods, deployments, networking, and contexts.

28 entries

Pods & workloads10

kubectl get pods -A

List pods across all namespaces

kubectl get pods -o wide

Pods with node & IP details

kubectl describe pod <name>

Detailed pod info & events

kubectl logs -f <pod>

Follow a pod's logs

kubectl logs <pod> -c <container> --previous

Previous container's logs

kubectl exec -it <pod> -- sh

Open a shell in a pod

kubectl get deploy

List deployments

kubectl rollout restart deploy/<name>

Restart a deployment

kubectl rollout undo deploy/<name>

Roll back to the previous revision

kubectl scale deploy/<name> --replicas=3

Scale a deployment

Apply & manage6

kubectl apply -f file.yaml

Create/update from a file

kubectl apply -k ./overlay

Apply a kustomize overlay

kubectl delete -f file.yaml

Delete resources from a file

kubectl get <res> -o yaml

Print a resource as YAML

kubectl explain <res>

Show a resource's schema docs

apiVersion: v1 kind: Pod metadata: name: demo spec: containers: - name: app image: nginx

Minimal pod manifest

Networking & config6

kubectl get svc

List services

kubectl port-forward svc/<name> 8080:80

Forward a local port to a service

kubectl get ingress

List ingresses

kubectl get cm,secret

List config maps and secrets

kubectl create secret generic s --from-literal=k=v

Create a secret

kubectl get secret s -o jsonpath='{.data.k}' | base64 -d

Decode a secret value

Contexts & debugging6

kubectl config get-contexts

List configured contexts

kubectl config use-context <name>

Switch the current context

kubectl config set-context --current --namespace=<ns>

Set default namespace

kubectl top pod

Pod CPU/memory usage

kubectl get events --sort-by=.lastTimestamp

Recent cluster events

kubectl debug -it <pod> --image=busybox

Attach an ephemeral debug container