Kubernetes Cheatsheet — Complete Quick Reference (2026)
DodaTech
Updated 2026-06-20
3 min read
In this tutorial, you'll learn about Kubernetes Cheatsheet. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
Kubernetes is an Orchestration platform for deploying, scaling, and managing containerized workloads across clusters, providing automated rollouts, service discovery, and self-healing.
kubectl Quick Commands
| Command | Description |
|---|---|
kubectl get pods |
List pods |
kubectl get pods -o wide |
Pods with node/ip |
kubectl get all -n namespace |
All resources in namespace |
kubectl describe pod name |
Detailed pod info |
kubectl logs pod-name |
Container logs |
kubectl logs -f pod-name |
Stream logs |
kubectl exec -it pod -- sh |
Shell into container |
kubectl apply -f file.yaml |
Create/update from file |
kubectl delete -f file.yaml |
Delete from file |
kubectl port-forward pod 8080:80 |
Forward local port |
kubectl get events --sort-by='.lastTimestamp' |
Recent events |
kubectl top pod |
Resource usage |
Pod
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels: { app: web }
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
resources:
requests: { cpu: "100m", memory: "128Mi" }
limits: { cpu: "500m", memory: "256Mi" }
Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deploy
spec:
replicas: 3
selector: { matchLabels: { app: web } }
template:
metadata: { labels: { app: web } }
spec:
containers:
- name: web
image: myapp:1.0
ports:
- containerPort: 3000
strategy:
type: RollingUpdate
rollingUpdate: { maxUnavailable: 1, maxSurge: 1 }
Service
| Type | Description |
|---|---|
ClusterIP |
Internal cluster IP (default) |
NodePort |
Expose on node port (30000–32767) |
LoadBalancer |
Cloud load balancer |
ExternalName |
DNS alias |
apiVersion: v1
kind: Service
metadata:
name: web-svc
spec:
selector: { app: web }
ports:
- port: 80
targetPort: 3000
type: ClusterIP
Namespaces
kubectl create namespace staging
kubectl config set-context --current --namespace=staging
kubectl get pods -n staging
ConfigMap & Secret
apiVersion: v1
kind: ConfigMap
metadata: { name: app-config }
data:
APP_ENV: production
DB_URL: postgres://db:5432
---
apiVersion: v1
kind: Secret
metadata: { name: app-secret }
type: Opaque
stringData:
API_KEY: sk-abc123 # base64 encoded automatically
Mount in pod: envFrom: [{ configMapRef: { name: app-config } }, { secretRef: { name: app-secret } }]
Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ingress
annotations: { nginx.ingress.kubernetes.io/rewrite-target: / }
spec:
rules:
- host: example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api-svc
port: { number: 80 }
Troubleshooting
kubectl describe pod failing-pod # events + conditions
kubectl logs failing-pod --previous # logs from crashed container
kubectl get events --field-selector involvedObject.name=failing-pod
kubectl exec -it failing-pod -- sh # inspect live
kubectl debug pod/failing-pod --image=busybox # ephemeral debug container
# Common issues: ImagePullBackOff (bad image), CrashLoopBackOff (app error),
# Pending (insufficient resources), ContainerCreating (volume issues)
Must-Know Items
- Use
kubectl apply(declarative) notkubectl run(imperative) for production - Pods are ephemeral — use Deployments for self-healing apps
- Resource requests guarantee scheduling; limits prevent runaway usage
- Probe types:
livenessProbe(restart container),readinessProbe(traffic),startupProbe(slow starts) ConfigMapstores non-sensitive data;Secretstores sensitive (base64, not encrypted)- Use namespaces to isolate environments; RBAC controls access
kubectl drain nodebefore maintenance;kubectl cordonprevents scheduling
See full Kubernetes tutorials for cluster administration and advanced deployments.
← Previous
CSS Grid Cheatsheet — Complete Quick Reference (2026)
Next →
Go Cheatsheet — Complete Quick Reference (2026)
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro