ENGIMY.IO - CHEATSHEET
K8S × QUICK REFERENCE
REFERENCE v1.0

Kubernetes Quick Reference

Everything you need day‑to‑day – cluster management, manifests, and debugging.

Core Concepts

Key Resources
  • Pod – smallest unit, one or more containers
  • Deployment – manages Pod replicas (rolling updates)
  • Service – stable network endpoint (ClusterIP, NodePort, LoadBalancer)
  • Ingress – HTTP/HTTPS routing
  • ConfigMap – configuration (non‑secret)
  • Secret – sensitive data (base64 encoded)
  • PersistentVolume (PV) – cluster storage
  • PersistentVolumeClaim (PVC) – storage request
  • StatefulSet – stateful apps (stable identities)
  • DaemonSet – one Pod per node
  • Job / CronJob – batch tasks
Kubernetes Architecture
  • Control Plane – API Server, etcd, Scheduler, Controller Manager
  • Node – Worker (kubelet, kube‑proxy, container runtime)
  • API Server – exposes REST API
  • etcd – key‑value store (cluster state)
  • Scheduler – assigns Pods to nodes
  • Controller Manager – runs controllers (Deployment, ReplicaSet, etc.)
  • kubelet – runs on nodes, manages Pods
  • kube‑proxy – network rules (Services)
  • Container Runtime – Docker, containerd, CRI‑O

kubectl Commands

Context & Configuration

# View current context
kubectl config current-context

# List contexts
kubectl config get-contexts

# Switch context
kubectl config use-context context-name

# View cluster info
kubectl cluster-info

# View API resources
kubectl api-resources
kubectl api-versions

Basic Operations

# Get resources
kubectl get pods
kubectl get pods -n namespace
kubectl get pods -o wide
kubectl get deployments
kubectl get services
kubectl get nodes
kubectl get all

# Watch resources (live updates)
kubectl get pods -w

# Describe resource
kubectl describe pod pod-name
kubectl describe deployment deploy-name
kubectl describe node node-name

# Create / Apply
kubectl apply -f manifest.yaml
kubectl apply -f manifest.yaml --dry-run=client  # validate only

# Delete
kubectl delete pod pod-name
kubectl delete -f manifest.yaml
kubectl delete deployment deploy-name

# Edit live resource
kubectl edit deployment deploy-name

# Scale deployment
kubectl scale deployment deploy-name --replicas=5

# Rollout status
kubectl rollout status deployment deploy-name

# Rollback deployment
kubectl rollout undo deployment deploy-name
kubectl rollout history deployment deploy-name

Pod Management

# View logs
kubectl logs pod-name
kubectl logs pod-name -c container-name
kubectl logs -f pod-name    # follow
kubectl logs --tail=100 pod-name

# Execute command in Pod
kubectl exec -it pod-name -- bash
kubectl exec -it pod-name -c container-name -- bash
kubectl exec pod-name -- ls -la

# Copy files
kubectl cp pod-name:/path/to/file ./local-file
kubectl cp ./local-file pod-name:/path/to/file

# Port forward
kubectl port-forward pod-name 8080:80

# Debug Pod (temporary)
kubectl debug -it pod-name --image=busybox --target=container-name

# Run one‑off Pod
kubectl run test-pod --image=nginx --restart=Never --rm -it -- /bin/bash

Namespaces

# List namespaces
kubectl get ns

# Create namespace
kubectl create ns my-namespace

# Set namespace for context
kubectl config set-context --current --namespace=my-namespace

# Delete namespace
kubectl delete ns my-namespace

Labels & Selectors

# Add / Modify labels
kubectl label pod pod-name app=backend
kubectl label pod pod-name app=backend --overwrite

# List with label filter
kubectl get pods -l app=backend
kubectl get pods -l 'app in (frontend, backend)'

# Delete with label filter
kubectl delete pods -l app=backend

YAML Manifests

Pod Manifest

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
  namespace: default
  labels:
    app: my-app
spec:
  containers:
    - name: nginx
      image: nginx:latest
      ports:
        - containerPort: 80
      env:
        - name: ENV_VAR
          value: "production"
      resources:
        requests:
          memory: "64Mi"
          cpu: "250m"
        limits:
          memory: "128Mi"
          cpu: "500m"
      livenessProbe:
        httpGet:
          path: /health
          port: 80
        initialDelaySeconds: 10
        periodSeconds: 5
      readinessProbe:
        httpGet:
          path: /ready
          port: 80
        initialDelaySeconds: 5
        periodSeconds: 3

Deployment Manifest

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
  labels:
    app: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: app
          image: my-image:latest
          ports:
            - containerPort: 8080
          envFrom:
            - configMapRef:
                name: app-config
            - secretRef:
                name: app-secrets

Service Manifest

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: ClusterIP   # NodePort, LoadBalancer
  selector:
    app: my-app
  ports:
    - port: 80
      targetPort: 8080
      protocol: TCP

Ingress Manifest

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - host: myapp.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: my-service
                port:
                  number: 80

ConfigMap Manifest

apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  app.properties: |
    server.port=8080
    log.level=DEBUG
  DATABASE_URL: "postgres://user:pass@db:5432/app"

Secret Manifest

apiVersion: v1
kind: Secret
metadata:
  name: app-secrets
type: Opaque
data:
  password: cGFzc3dvcmQ=   # base64 encoded

# Create secret from literal
kubectl create secret generic app-secrets --from-literal=password=secret

# Create secret from file
kubectl create secret generic app-secrets --from-file=./secrets.env

PersistentVolumeClaim Manifest

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: app-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: standard

StatefulSet Manifest

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: my-statefulset
spec:
  serviceName: my-service
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: app
          image: my-image:latest
          ports:
            - containerPort: 8080
          volumeMounts:
            - name: data
              mountPath: /data
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 10Gi

Job Manifest

apiVersion: batch/v1
kind: Job
metadata:
  name: my-job
spec:
  completions: 5
  parallelism: 2
  template:
    spec:
      containers:
        - name: worker
          image: busybox
          command: ["echo", "Job done"]
      restartPolicy: OnFailure

Helm (Package Manager)

# Install Helm
brew install helm  # Mac
choco install kubernetes-helm # Windows

# Add repository
helm repo add stable https://charts.helm.sh/stable
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update

# Search for charts
helm search repo nginx

# Install chart
helm install my-release bitnami/nginx
helm install my-release bitnami/nginx --namespace my-ns

# Install with custom values
helm install my-release bitnami/nginx -f values.yaml
helm install my-release bitnami/nginx --set replicaCount=3

# List releases
helm list
helm list -n my-ns

# Upgrade release
helm upgrade my-release bitnami/nginx -f values.yaml

# Rollback release
helm rollback my-release 1

# Uninstall
helm uninstall my-release

# Create chart
helm create my-chart

# Lint chart
helm lint ./my-chart

# Package chart
helm package my-chart

values.yaml Example

# Custom values for Nginx chart
replicaCount: 3
image:
  repository: nginx
  tag: alpine
  pullPolicy: IfNotPresent
service:
  type: LoadBalancer
  port: 80
ingress:
  enabled: true
  hostname: myapp.example.com
resources:
  limits:
    cpu: 500m
    memory: 512Mi
  requests:
    cpu: 250m
    memory: 256Mi

Common Troubleshooting Commands

# Check node status
kubectl get nodes
kubectl describe node node-name

# Check events
kubectl get events --sort-by='.lastTimestamp'
kubectl get events -n namespace

# Check Pod status
kubectl get pods
kubectl describe pod pod-name

# Check deployment
kubectl rollout status deployment deploy-name
kubectl rollout history deployment deploy-name

# Check logs of failed Pod
kubectl logs pod-name --previous
kubectl logs pod-name -c container-name --tail=50

# Check service
kubectl describe service service-name

# Check ingress
kubectl describe ingress ingress-name

# Check PVC
kubectl get pvc
kubectl describe pvc pvc-name

# Check secrets
kubectl get secrets
kubectl describe secret secret-name

# Check configmaps
kubectl get configmaps
kubectl describe configmap configmap-name

Resource Limits & Requests

Resource Unit Description
CPU m (millicores) 100m = 0.1 vCPU
vCPU 1 vCPU = 1000m
Memory Mi, Gi Mi = mebibytes (1024²), Gi = gibibytes (1024³)
M, G M = megabytes (1000²), G = gigabytes (1000³)

Resource Requests vs Limits

  • Requests – minimum guaranteed resources
  • Limits – maximum allowed resources
  • If limit exceeded, Pod may be throttled (CPU) or OOMKilled (memory)
  • Always set both requests and limits for production

Best Practices

  • Use namespaces – separate environments (dev, staging, prod)
  • Use labels – organise and select resources
  • Use probes – liveness and readiness for reliability
  • Set resource limits – prevent resource starvation
  • Use ConfigMaps & Secrets – externalise configuration
  • Use network policies – restrict traffic between Pods
  • Use PodDisruptionBudgets – maintain availability during disruptions
  • Use Horizontal Pod Autoscaler – auto‑scale based on CPU/memory
  • Use Vertical Pod Autoscaler – auto‑adjust resource requests
  • Use RBAC – least privilege for users and services
  • Use service accounts – for Pods accessing the API
  • Use Helm for package management – version and share charts
  • Use GitOps – ArgoCD, Flux for declarative deployments
  • Monitor – Prometheus, Grafana, CloudWatch, Datadog
  • Logging – ELK/EFK stack (Elasticsearch, Fluentd, Kibana)
  • Backup etcd – periodic backups of cluster state

kubectl Cheat Sheet

Task Command
List Pods kubectl get pods
List Deployments kubectl get deployments
List Services kubectl get services
List Nodes kubectl get nodes
View Pod logs kubectl logs pod-name
Exec into Pod kubectl exec -it pod-name -- bash
Apply manifest kubectl apply -f manifest.yaml
Delete manifest kubectl delete -f manifest.yaml
Scale Deployment kubectl scale deployment name --replicas=5
Rollout Restart kubectl rollout restart deployment name
Port forward kubectl port-forward pod-name 8080:80
Create secret kubectl create secret generic name --from-literal=key=value
Create configmap kubectl create configmap name --from-literal=key=value
📌 Quick Reference
kubectl: get, describe, apply, delete, logs, exec
Resources: Pod, Deployment, Service, Ingress, ConfigMap, Secret, PVC, StatefulSet
Namespaces: isolate environments (dev, staging, prod)
Labels: organise and select resources (app, env, tier)
Probes: liveness (alive), readiness (ready to serve)
Helm: repo add, install, upgrade, rollback, uninstall
Best practices: resource limits, probes, config externalisation, RBAC, namespaces, monitoring
← Back to All Cheatsheets