Kubernetes Cheat Sheet

The control-plane objects behind every cluster — workloads, services, config, and storage, managed through the API.

Kubernetes6 sections · 42 commands
⌘K

Core Objects

10
kubectl get nodes

Cluster nodes and status

kubectl get namespaces

List namespaces

kubectl get pods -A

Pods in every namespace

kubectl get deployments

Deployments (ReplicaSet rollout)

kubectl get services

Service endpoints

kubectl get configmaps

Non-secret config

kubectl get secrets

Secret objects

kubectl get pvc

Persistent volume claims

kubectl get events --sort-by=.lastTimestamp

Cluster events, newest first

kubectl get all --namespace NS

Common workloads in a namespace

Workloads & Controllers

9
kubectl create deployment NAME --image=IMAGE

Create a deployment

kubectl set image deployment/NAME app=IMAGE:NEW

Rolling image update

kubectl scale deployment/NAME --replicas=5

Scale a deployment

kubectl rollout status deploy/NAME

Wait for rollout to finish

kubectl rollout undo deploy/NAME

Roll back to the previous revision

kubectl rollout history deploy/NAME

Revision list

kubectl get pods --show-labels

Pods with their labels

kubectl get jobs / cronjobs

One-shot and scheduled work

kubectl get daemonsets -A

Node-wide controllers

Networking & Service

6
kubectl expose deploy/NAME --port=80 --target-port=8080

Create a ClusterIP service

kubectl expose deploy/NAME --type=NodePort --port=80

Expose on a node port

kubectl get endpoints

Backing pods behind a service

kubectl port-forward svc/NAME 8080:80

Tunnel a local port to a service

kubectl get ingress

L7 routing rules

kubectl exec POD -- curl -s http://svc

Test internal DNS from a pod

Config & Secrets

7
kubectl create configmap NAME --from-file=config/

ConfigMap from files

kubectl create secret generic NAME --from-literal=KEY=value

Secret from a literal

kubectl create secret generic NAME --from-file=KEY=./file

Secret from a file

kubectl get secret NAME -o yaml | base64 -d

Read a secret value

kubectl apply -f manifest.yml

Declarative apply (preferred)

kubectl diff -f manifest.yml

Preview changes before applying

kubectl delete -f manifest.yml

Delete what the file defines

Scheduling & Resources

5
kubectl taint nodes NODE key=value:NoSchedule

Prevent scheduling on a node

kubectl label nodes NODE disktype=ssd

Label a node for nodeSelector

kubectl top nodes

Node CPU/memory usage

kubectl top pods -n NS

Pod resource usage

kubectl describe node NODE

Capacity, allocatable, and pods

Contexts & Config

5
kubectl config get-contexts

List available contexts

kubectl config use-context NAME

Switch contexts

kubectl config current-context

Active context

kubectl config view

Show merged kubeconfig

kubectl --context NAME get pods

One-off context override