Kubernetes Cheat Sheet
kubectl commands, pod management, deployments, and cluster operations.
3 PagesAdvancedApr 28, 2026
kubectl Basics
Core cluster inspection commands.
bash
kubectl get pods # List podskubectl get pods -n my-namespace # In a namespacekubectl describe pod <name> # Detailed infokubectl logs <pod-name> # View logskubectl exec -it <pod-name> -- sh # Shell into pod
Deployments
Manage application deployments.
bash
kubectl apply -f deployment.yamlkubectl get deploymentskubectl scale deployment my-app --replicas=5kubectl rollout status deployment my-appkubectl rollout undo deployment my-app
Services
Expose pods on the network.
yaml
apiVersion: v1kind: Servicemetadata: name: my-servicespec: selector: app: my-app ports: - port: 80 targetPort: 8080 type: ClusterIP
ConfigMaps & Secrets
Create and consume configuration and secrets.
bash
kubectl create configmap app-cfg --from-literal=LOG=debugkubectl create configmap app-cfg --from-file=./config/kubectl create secret generic db --from-literal=pass=s3cret# Inspect (secrets are base64-encoded)kubectl get secret db -o jsonpath='{.data.pass}' | base64 -d# Reference in a pod via envFrom / valueFrom.secretKeyRefkubectl set env deploy/api --from=configmap/app-cfg
Debugging Pods
Inspect, exec into, and troubleshoot workloads.
bash
kubectl describe pod <pod> # events + statuskubectl logs <pod> -c <container> -f # follow logskubectl logs <pod> --previous # crashed container logskubectl exec -it <pod> -- sh # shell insidekubectl port-forward svc/api 8080:80 # local tunnelkubectl debug <pod> -it --image=busybox --target=<ctr>kubectl get events --sort-by=.lastTimestamp
Resources & Autoscaling
Requests, limits, and horizontal scaling.
yaml
resources: requests: # scheduler guarantees cpu: "250m" memory: "256Mi" limits: # hard ceiling (OOMKill if exceeded) cpu: "500m" memory: "512Mi"---# Autoscale on CPU# kubectl autoscale deploy api --min=2 --max=10 --cpu-percent=70# kubectl scale deploy api --replicas=5
Health Probes
The three probe types and when each fires.
- livenessProbe- restarts the container when it fails; detects deadlocks
- readinessProbe- removes the pod from Service endpoints until it passes
- startupProbe- gates the other probes until a slow-starting app is up
- initialDelaySeconds- wait before the first probe check runs
- failureThreshold- consecutive failures before the probe acts
- exec / httpGet / tcpSocket- the three ways a probe can test container health
Pro Tip
Use kubectl get pods -o wide and kubectl top pods to quickly diagnose scheduling and resource issues.
Was this cheat sheet helpful?
Explore Topics
#Kubernetes#KubernetesCheatSheet#DevOps#Advanced#KubectlBasics#Deployments#Services#ConfigMapsSecrets#CheatSheet#SkillVeris