Skip to content

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) not kubectl 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)
  • ConfigMap stores non-sensitive data; Secret stores sensitive (base64, not encrypted)
  • Use namespaces to isolate environments; RBAC controls access
  • kubectl drain node before maintenance; kubectl cordon prevents scheduling
What is the difference between a Pod and a Deployment?

A Pod is the smallest deployable unit — one or more containers sharing network and storage. A Deployment manages ReplicaSets, providing declarative updates, rollbacks, and scaling. Always use Deployments for production workloads; Pods are typically created by controllers, not directly.

How do liveness and readiness probes differ?

A liveness probe checks if the container is alive and restarts it on failure. A readiness probe checks if the container is ready to serve traffic — if it fails, the Pod is removed from Service endpoints. Use liveness for Deadlock detection, readiness for startup/load dependencies.

See full Kubernetes tutorials for cluster administration and advanced deployments.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro