{"id":"6b09aa7e5a5e2dbc3f20a47b","slug":"kubernetes-basics","title":"Kubernetes basics – Pods, Deployments, Services, Gateway API, ConfigMaps and Secrets, probes, resources, HPA and rolling updates","summary":"We run the dumpling-shop application (a NestJS API, an nginx frontend, PostgreSQL and Redis) on Kubernetes and meet the key objects along the way: Pod, Deployment, StatefulSet, Service, Gateway API and Ingress, ConfigMap and Secret, startup/liveness/readiness probes, requests and limits, HPA autoscaling and rolling updates with rollback – with YAML manifests and kubectl sessions.","servedLang":"en","availableLangs":["pl","en"],"topics":["kubernetes","docker","microservices"],"techs":["general"],"tags":["kubernetes","kubectl","deployment","statefulset","service","gateway-api","ingress","configmap","secret","probes","hpa","rolling-update","kustomize"],"level":"intermediate","kind":"tutorial","access":"public","status":"published","cover":null,"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"readingMinutes":16,"stats":{"views":2,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-27T16:06:22.591Z","updatedAt":"2026-11-27T17:24:32.645Z","requestedLang":"en","theme":{"hero":"classic","heroMedia":null,"accent":"amber","background":"grid","weaveResources":true,"toc":"right"},"seoDescription":"Kubernetes step by step for developers – cluster architecture, Pod, Deployment, ReplicaSet, StatefulSet, ClusterIP Service, Gateway API HTTPRoute vs Ingress, ConfigMap, Secret, startupProbe, livenessProbe, readinessProbe, requests and limits, HorizontalPodAutoscaler, rolling update, rollout undo, Ku","wordCount":3150,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Kubernetes has a reputation as a tool you cannot learn without a week of documentation. Yet running a typical web application takes a dozen or so concepts – and each of them solves a concrete problem you would have with servers anyway: restarting after a crash, several copies behind one address, per-environment configuration, updates without downtime, more machines under more traffic. In this tutorial you will move the application from the "},{"type":"text","text":"Docker tutorial","marks":[{"type":"link","attrs":{"href":"/en/articles/docker-for-developers"}}]},{"type":"text","text":" into a cluster and see why each object exists."}]},{"type":"callout","attrs":{"variant":"info","title":"In short"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"You describe the desired state and Kubernetes maintains it.","marks":[{"type":"bold"}]},{"type":"text","text":" A manifest says \"I want 2 replicas of API version 1.0.0\"; controllers loop, compare that with reality and fix differences (restart, a new pod on another node)."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"A Deployment manages stateless pods, a Service gives them a stable address, and the Gateway API (or Ingress) lets traffic in from outside.","marks":[{"type":"bold"}]},{"type":"text","text":" Configuration goes into a ConfigMap, passwords into a Secret."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Probes and resources are not extras","marks":[{"type":"bold"}]},{"type":"text","text":": readiness decides whether a pod receives traffic, liveness whether to restart it, and CPU/memory requests are the basis of scheduling and autoscaling (HPA)."}]}]}]}]},{"type":"callout","attrs":{"variant":"tip","title":"What you will build"},"content":[{"type":"paragraph","content":[{"type":"text","text":"A set of manifests (with Kustomize) for the dumpling-shop app: a namespace with Pod Security, a ConfigMap and a Secret, PostgreSQL 18 as a StatefulSet with a persistent volume, Redis, a NestJS API (2 replicas, three kinds of probes, requests and limits, a hardened security context, a zero-downtime rolling update), an nginx frontend, routing through the Gateway API (and alternatively Ingress), and an HPA that scales the API from 2 to 10 replicas. You can download the code as a ZIP."}]}]},{"type":"paragraph","content":[{"type":"text","text":"Prerequisites:","marks":[{"type":"bold"}]},{"type":"text","text":" "},{"type":"text","text":"Docker for developers","marks":[{"type":"link","attrs":{"href":"/en/articles/docker-for-developers"}}]},{"type":"text","text":" (the "},{"type":"text","text":"pierogi-api","marks":[{"type":"code"}]},{"type":"text","text":" and "},{"type":"text","text":"pierogi-web","marks":[{"type":"code"}]},{"type":"text","text":" images), "},{"type":"text","text":"kubectl","marks":[{"type":"code"}]},{"type":"text","text":" and a local cluster: kind, minikube, k3d or Kubernetes in Docker Desktop."}]},{"type":"stats","attrs":{"items":[{"value":"2 → 10","label":"API replicas","hint":"HPA at 70% CPU relative to the request"},{"value":"0","label":"downtime during updates","hint":"`maxUnavailable: 0`, readiness"},{"value":"3","label":"kinds of probes","hint":"startup, liveness, readiness"},{"value":"1","label":"deploy command","hint":"`kubectl apply -k k8s/`"}]}},{"type":"heading","attrs":{"level":2,"id":"how-a-cluster-is-built"},"content":[{"type":"text","text":"How a cluster is built"}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"flowchart LR\n  U[\"kubectl / CI / Argo CD\"] -->|\"HTTPS: YAML manifests\"| API[\"kube-apiserver\"]\n  subgraph CP[\"Control plane\"]\n    API <--> ETCD[(\"etcd<br/>cluster state\")]\n    SCH[\"scheduler<br/>picks a node for a pod\"] --> API\n    CM[\"controller-manager<br/>Deployment, ReplicaSet, HPA…\"] --> API\n  end\n  subgraph N1[\"Node 1\"]\n    K1[\"kubelet\"] --> CR1[\"containerd\"] --> P1[\"pods\"]\n    KP1[\"kube-proxy / CNI\"]\n  end\n  subgraph N2[\"Node 2\"]\n    K2[\"kubelet\"] --> CR2[\"containerd\"] --> P2[\"pods\"]\n  end\n  API <--> K1\n  API <--> K2","caption":"The control plane and worker nodes"}},{"type":"paragraph","content":[{"type":"text","text":"Everything goes through the "},{"type":"text","text":"kube-apiserver","marks":[{"type":"bold"}]},{"type":"text","text":": you store the desired state, "},{"type":"text","text":"controllers","marks":[{"type":"bold"}]},{"type":"text","text":" compare it with the actual state and act (e.g. the ReplicaSet controller creates missing pods), the "},{"type":"text","text":"scheduler","marks":[{"type":"bold"}]},{"type":"text","text":" assigns pods to nodes, and the "},{"type":"text","text":"kubelet","marks":[{"type":"bold"}]},{"type":"text","text":" on each node runs containers through containerd and reports their status. In a managed cluster (EKS, GKE, AKS) the provider runs the control plane."}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Object"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Used for"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"In this application"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Pod"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the smallest unit: one or more containers sharing an IP"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"every API, web and redis replica"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Deployment → ReplicaSet"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"stateless replicas, rolling updates, rollback"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"api, web, redis"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"StatefulSet"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"a stable name ("},{"type":"text","text":"postgres-0","marks":[{"type":"code"}]},{"type":"text","text":") and a volume per replica"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"postgres"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Service"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"a stable DNS name and load balancing across pods"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"api","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"web","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"postgres","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"redis","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Gateway + HTTPRoute (or Ingress)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"HTTP traffic from outside, routing by path and host"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"/api","marks":[{"type":"code"}]},{"type":"text","text":" → api, "},{"type":"text","text":"/","marks":[{"type":"code"}]},{"type":"text","text":" → web"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"ConfigMap / Secret"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"configuration and sensitive data outside the image"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"api-config","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"db-credentials","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"HorizontalPodAutoscaler"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"replica count driven by metrics"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"api: 2–10"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Namespace"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"a boundary for names, permissions and quotas"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"pierogi","marks":[{"type":"code"}]}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"step-1-a-local-cluster-and-images"},"content":[{"type":"text","text":"Step 1. A local cluster and images"}]},{"type":"codeBlock","attrs":{"language":"bash"},"content":[{"type":"text","text":"kind create cluster --name pierogi            # or: minikube start / k3d cluster create\ndocker build -t pierogi-api:1.0.0 --target runtime ./api\ndocker build -t pierogi-web:1.0.0 --target runtime ./web\nkind load docker-image pierogi-api:1.0.0 pierogi-web:1.0.0 --name pierogi   # minikube: minikube image load …\nkubectl get nodes"}]},{"type":"paragraph","content":[{"type":"text","text":"In a real cluster you push images to a registry (GHCR, ECR, Artifact Registry) and reference the full path with an immutable tag or a digest in the manifest. A local cluster cannot see the images in your Docker, which is why you load them."}]},{"type":"heading","attrs":{"level":2,"id":"step-2-namespace-configuration-and-a-secret"},"content":[{"type":"text","text":"Step 2. Namespace, configuration and a secret"}]},{"type":"codeGroup","attrs":{"title":"Namespace, ConfigMap and Kustomize"},"content":[{"type":"codeBlock","attrs":{"language":"yaml","filename":"k8s/namespace.yaml"},"content":[{"type":"text","text":"apiVersion: v1\nkind: Namespace\nmetadata:\n  name: pierogi\n  labels:\n    app.kubernetes.io/part-of: pierogi\n    # Pod Security Admission: reject pods that run as root, privileged, etc.\n    pod-security.kubernetes.io/enforce: restricted"}]},{"type":"codeBlock","attrs":{"language":"yaml","filename":"k8s/config.yaml"},"content":[{"type":"text","text":"apiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: api-config\ndata:\n  PORT: \"3000\"\n  REDIS_URL: redis://redis:6379\n---\napiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: postgres-init\ndata:\n  init.sql: |\n    CREATE TABLE IF NOT EXISTS menu (id TEXT PRIMARY KEY, name TEXT NOT NULL, price_cents INTEGER NOT NULL);\n    INSERT INTO menu VALUES ('ruskie', 'Ruskie', 2400), ('meat', 'With meat', 2700), ('spinach', 'Spinach & feta', 2600)\n    ON CONFLICT (id) DO NOTHING;\n# The Secret is NOT stored in git – create it once per environment:\n#   kubectl -n pierogi create secret generic db-credentials --from-literal=password=\"$(openssl rand -base64 24)\"\n# In production: External Secrets Operator / Sealed Secrets (see the production article)."}]},{"type":"codeBlock","attrs":{"language":"yaml","filename":"k8s/kustomization.yaml"},"content":[{"type":"text","text":"# kubectl apply -k .   (Kustomize is built into kubectl)\napiVersion: kustomize.config.k8s.io/v1beta1\nkind: Kustomization\nnamespace: pierogi\nresources:\n  - namespace.yaml\n  - config.yaml\n  - postgres.yaml\n  - redis.yaml\n  - api.yaml\n  - web.yaml\n  - hpa.yaml\n  # - gateway.yaml   # after installing a Gateway API controller\nlabels:\n  - pairs:\n      app.kubernetes.io/part-of: pierogi"}]}]},{"type":"codeBlock","attrs":{"language":"bash"},"content":[{"type":"text","text":"kubectl apply -f k8s/namespace.yaml\nkubectl -n pierogi create secret generic db-credentials --from-literal=password=\"$(openssl rand -base64 24)\"\nkubectl apply -k k8s/"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"A ConfigMap","marks":[{"type":"bold"}]},{"type":"text","text":" holds configuration that differs between environments but is not secret. Changing a ConfigMap does not restart pods – environment variables are read at startup, so after a change run "},{"type":"text","text":"kubectl rollout restart deployment/api","marks":[{"type":"code"}]},{"type":"text","text":" (or add a config checksum to the pod template, as in the "},{"type":"text","text":"production tutorial","marks":[{"type":"link","attrs":{"href":"/en/articles/kubernetes-production"}}]},{"type":"text","text":")."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"A Secret","marks":[{"type":"bold"}]},{"type":"text","text":" is just base64-encoded data, not encryption. Don't commit it to the repository – create it with a command or sync it from a secret manager (External Secrets, Sealed Secrets)."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The ","marks":[{"type":"bold"}]},{"type":"text","text":"pod-security.kubernetes.io/enforce: restricted","marks":[{"type":"code"}]},{"type":"text","text":" label","marks":[{"type":"bold"}]},{"type":"text","text":" makes the cluster reject pods running as root or without security restrictions. All manifests in this tutorial comply."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Kustomize","marks":[{"type":"bold"}]},{"type":"text","text":" (built into "},{"type":"text","text":"kubectl -k","marks":[{"type":"code"}]},{"type":"text","text":") assembles manifests and sets the namespace and labels. Per-environment variants are overlays instead of copied files."}]}]}]},{"type":"heading","attrs":{"level":2,"id":"step-3-data-postgresql-as-a-statefulset-and-redis"},"content":[{"type":"text","text":"Step 3. Data: PostgreSQL as a StatefulSet, and Redis"}]},{"type":"codeGroup","attrs":{"title":"PostgreSQL (StatefulSet + headless Service) and Redis"},"content":[{"type":"codeBlock","attrs":{"language":"yaml","filename":"k8s/postgres.yaml"},"content":[{"type":"text","text":"# Fine for development and learning. In production prefer a managed database\n# (RDS, Cloud SQL, Azure Database) or an operator such as CloudNativePG.\napiVersion: v1\nkind: Service\nmetadata:\n  name: postgres\nspec:\n  clusterIP: None # headless: DNS \"postgres\" points straight at the pod\n  selector: { app: postgres }\n  ports:\n    - name: postgres\n      port: 5432\n---\napiVersion: apps/v1\nkind: StatefulSet\nmetadata:\n  name: postgres\nspec:\n  serviceName: postgres\n  replicas: 1\n  selector:\n    matchLabels: { app: postgres }\n  template:\n    metadata:\n      labels: { app: postgres }\n    spec:\n      securityContext:\n        runAsNonRoot: true\n        runAsUser: 70 # \"postgres\" user in the alpine image\n        fsGroup: 70\n        seccompProfile: { type: RuntimeDefault }\n      containers:\n        - name: postgres\n          image: postgres:18-alpine\n          ports:\n            - name: postgres\n              containerPort: 5432\n          env:\n            - { name: POSTGRES_DB, value: pierogi }\n            - { name: POSTGRES_USER, value: pierogi }\n            - name: POSTGRES_PASSWORD\n              valueFrom:\n                secretKeyRef: { name: db-credentials, key: password }\n          readinessProbe:\n            exec:\n              command: [\"pg_isready\", \"-U\", \"pierogi\", \"-d\", \"pierogi\"]\n            periodSeconds: 5\n          resources:\n            requests: { cpu: 100m, memory: 256Mi }\n            limits: { memory: 512Mi }\n          securityContext:\n            allowPrivilegeEscalation: false\n            capabilities: { drop: [\"ALL\"] }\n          volumeMounts:\n            - { name: data, mountPath: /var/lib/postgresql }\n            - { name: init, mountPath: /docker-entrypoint-initdb.d, readOnly: true }\n            - { name: run, mountPath: /var/run/postgresql }\n      volumes:\n        - name: init\n          configMap: { name: postgres-init }\n        - name: run\n          emptyDir: {}\n  volumeClaimTemplates:\n    - metadata:\n        name: data\n      spec:\n        accessModes: [\"ReadWriteOnce\"]\n        resources:\n          requests: { storage: 1Gi }"}]},{"type":"codeBlock","attrs":{"language":"yaml","filename":"k8s/redis.yaml"},"content":[{"type":"text","text":"apiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: redis\nspec:\n  replicas: 1\n  selector:\n    matchLabels: { app: redis }\n  template:\n    metadata:\n      labels: { app: redis }\n    spec:\n      securityContext:\n        runAsNonRoot: true\n        runAsUser: 999\n        seccompProfile: { type: RuntimeDefault }\n      containers:\n        - name: redis\n          image: redis:8-alpine\n          args: [\"--save\", \"\", \"--appendonly\", \"no\"]\n          ports:\n            - { name: redis, containerPort: 6379 }\n          readinessProbe:\n            exec:\n              command: [\"redis-cli\", \"ping\"]\n            periodSeconds: 5\n          resources:\n            requests: { cpu: 50m, memory: 64Mi }\n            limits: { memory: 128Mi }\n          securityContext:\n            allowPrivilegeEscalation: false\n            capabilities: { drop: [\"ALL\"] }\n---\napiVersion: v1\nkind: Service\nmetadata:\n  name: redis\nspec:\n  selector: { app: redis }\n  ports:\n    - { name: redis, port: 6379, targetPort: redis }"}]}]},{"type":"paragraph","content":[{"type":"text","text":"A StatefulSet gives the pod a stable name ("},{"type":"text","text":"postgres-0","marks":[{"type":"code"}]},{"type":"text","text":") and its own PersistentVolumeClaim that survives restarts and rescheduling. The headless Service ("},{"type":"text","text":"clusterIP: None","marks":[{"type":"code"}]},{"type":"text","text":") makes the name "},{"type":"text","text":"postgres","marks":[{"type":"code"}]},{"type":"text","text":" point straight at the pod. That is enough for learning and test environments; a production database is better left to a managed service or an operator (e.g. CloudNativePG) that handles replication, backups and failover."}]},{"type":"heading","attrs":{"level":2,"id":"step-4-api-a-deployment-with-probes-resources-and-a-hardened-security-context"},"content":[{"type":"text","text":"Step 4. API: a Deployment with probes, resources and a hardened security context"}]},{"type":"codeGroup","attrs":{"title":"API Deployment and Service"},"content":[{"type":"codeBlock","attrs":{"language":"yaml","filename":"k8s/api.yaml"},"content":[{"type":"text","text":"apiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: api\n  labels: { app: api }\nspec:\n  replicas: 2\n  revisionHistoryLimit: 5\n  strategy:\n    type: RollingUpdate\n    rollingUpdate:\n      maxSurge: 1 # one extra pod during the update\n      maxUnavailable: 0 # never go below the desired number of ready pods\n  selector:\n    matchLabels: { app: api }\n  template:\n    metadata:\n      labels: { app: api }\n    spec:\n      terminationGracePeriodSeconds: 30\n      securityContext:\n        runAsNonRoot: true\n        runAsUser: 1000 # \"node\" user from the image\n        seccompProfile: { type: RuntimeDefault }\n      containers:\n        - name: api\n          image: pierogi-api:1.0.0 # in a real cluster: ghcr.io/<org>/pierogi-api:1.0.0 (immutable tag or digest)\n          imagePullPolicy: IfNotPresent\n          ports:\n            - { name: http, containerPort: 3000 }\n          envFrom:\n            - configMapRef: { name: api-config }\n          env:\n            - name: POSTGRES_PASSWORD\n              valueFrom:\n                secretKeyRef: { name: db-credentials, key: password }\n            - name: DATABASE_URL # $(VAR) expands a variable defined above\n              value: postgres://pierogi:$(POSTGRES_PASSWORD)@postgres:5432/pierogi\n          startupProbe: # gives a slow start up to 30 × 2 s before liveness kicks in\n            httpGet: { path: /api/live, port: http }\n            periodSeconds: 2\n            failureThreshold: 30\n          livenessProbe: # \"is the process stuck?\" → restart the container\n            httpGet: { path: /api/live, port: http }\n            periodSeconds: 10\n            failureThreshold: 3\n          readinessProbe: # \"can it serve traffic?\" → in/out of the Service endpoints\n            httpGet: { path: /api/health, port: http }\n            periodSeconds: 5\n            failureThreshold: 2\n          resources:\n            requests: { cpu: 100m, memory: 128Mi } # what the scheduler reserves\n            limits: { memory: 256Mi } # above this the container is OOM-killed\n          lifecycle:\n            preStop: # let endpoints/load balancers stop sending traffic before SIGTERM\n              sleep: { seconds: 5 }\n          securityContext:\n            allowPrivilegeEscalation: false\n            readOnlyRootFilesystem: true\n            capabilities: { drop: [\"ALL\"] }\n---\napiVersion: v1\nkind: Service\nmetadata:\n  name: api\nspec:\n  selector: { app: api }\n  ports:\n    - { name: http, port: 3000, targetPort: http }"}]}]},{"type":"heading","attrs":{"level":3,"id":"three-probes-three-questions"},"content":[{"type":"text","text":"Three probes, three questions"}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Probe"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Question"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"On failure"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Our endpoint"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"startupProbe","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"has the app finished starting?"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"after "},{"type":"text","text":"failureThreshold","marks":[{"type":"code"}]},{"type":"text","text":" – restart; until then the other probes wait"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"/api/live","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"livenessProbe","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"is the process stuck?"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the container is restarted"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"/api/live","marks":[{"type":"code"}]},{"type":"text","text":" (no database!)"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"readinessProbe","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"can it serve traffic right now?"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the pod leaves the Service endpoints, "},{"type":"text","text":"no restart","marks":[{"type":"bold"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"/api/health","marks":[{"type":"code"}]},{"type":"text","text":" (database + Redis)"}]}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"The most common mistake is a liveness probe that checks the database. When the database has a brief outage, Kubernetes restarts "},{"type":"text","text":"every","marks":[{"type":"bold"}]},{"type":"text","text":" API pod – and after the restart they still cannot connect. That is why liveness asks only about the process itself, while readiness checks dependencies: a pod without its database stops receiving traffic but is not killed. You can verify it by stopping the database:"}]},{"type":"output","attrs":{"title":"kubectl: database stopped – API pods not ready, but no restarts (sample output)","language":"bash","content":"$ kubectl -n pierogi scale statefulset postgres --replicas=0\nstatefulset.apps/postgres scaled\n\n$ kubectl -n pierogi get pods -l app=api\nNAME                   READY   STATUS    RESTARTS   AGE\napi-6d9c7b8f5d-7xk2p   0/1     Running   0          12m\napi-6d9c7b8f5d-qm4zt   0/1     Running   0          12m\n\n$ kubectl -n pierogi scale statefulset postgres --replicas=1   # after a moment the pods are back to 1/1"}},{"type":"heading","attrs":{"level":3,"id":"requests-limits-and-qos-classes"},"content":[{"type":"text","text":"Requests, limits and QoS classes"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"requests","marks":[{"type":"code"}]},{"type":"text","text":" – how much the scheduler reserves for the pod. A pod lands only on a node with that much free capacity; the HPA percentage is also computed against the CPU request."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"limits.memory","marks":[{"type":"code"}]},{"type":"text","text":" – exceeding it kills the container ("},{"type":"text","text":"OOMKilled","marks":[{"type":"code"}]},{"type":"text","text":"). A CPU limit does not kill, it throttles – which is why this project does not set one."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The QoS class","marks":[{"type":"bold"}]},{"type":"text","text":" follows from these settings: "},{"type":"text","text":"Guaranteed","marks":[{"type":"code"}]},{"type":"text","text":" (requests = limits for CPU and memory), "},{"type":"text","text":"Burstable","marks":[{"type":"code"}]},{"type":"text","text":" (like our API) or "},{"type":"text","text":"BestEffort","marks":[{"type":"code"}]},{"type":"text","text":" (nothing set – first to be evicted when a node runs out of memory)."}]}]}]},{"type":"heading","attrs":{"level":3,"id":"other-details-of-the-manifest"},"content":[{"type":"text","text":"Other details of the manifest"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"$(POSTGRES_PASSWORD)","marks":[{"type":"code"}]},{"type":"text","text":" inside ","marks":[{"type":"bold"}]},{"type":"text","text":"DATABASE_URL","marks":[{"type":"code"}]},{"type":"text","text":" – Kubernetes expands references to variables defined earlier in the same container, so the password stays in the Secret."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"preStop: sleep 5","marks":[{"type":"code"}]},{"type":"text","text":" – before the container receives "},{"type":"text","text":"SIGTERM","marks":[{"type":"code"}]},{"type":"text","text":", the pod is removed from the endpoints, but kube-proxy and load balancers need a moment to notice. Waiting five seconds prevents 502 errors during updates."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"securityContext","marks":[{"type":"code"}]},{"type":"text","text":": no root, no privilege escalation, dropped capabilities, a read-only filesystem, a seccomp profile. The Node app writes nothing to disk, so "},{"type":"text","text":"readOnlyRootFilesystem","marks":[{"type":"code"}]},{"type":"text","text":" does not get in the way."}]}]}]},{"type":"heading","attrs":{"level":2,"id":"step-5-the-frontend-and-traffic-from-outside"},"content":[{"type":"text","text":"Step 5. The frontend and traffic from outside"}]},{"type":"codeGroup","attrs":{"title":"Frontend Deployment and Service"},"content":[{"type":"codeBlock","attrs":{"language":"yaml","filename":"k8s/web.yaml"},"content":[{"type":"text","text":"apiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: web\n  labels: { app: web }\nspec:\n  replicas: 2\n  selector:\n    matchLabels: { app: web }\n  template:\n    metadata:\n      labels: { app: web }\n    spec:\n      securityContext:\n        runAsNonRoot: true\n        runAsUser: 101 # nginx-unprivileged\n        seccompProfile: { type: RuntimeDefault }\n      containers:\n        - name: web\n          image: pierogi-web:1.0.0\n          imagePullPolicy: IfNotPresent\n          ports:\n            - { name: http, containerPort: 8080 }\n          readinessProbe:\n            httpGet: { path: /healthz, port: http }\n            periodSeconds: 5\n          livenessProbe:\n            httpGet: { path: /healthz, port: http }\n            periodSeconds: 15\n          resources:\n            requests: { cpu: 20m, memory: 32Mi }\n            limits: { memory: 64Mi }\n          securityContext:\n            allowPrivilegeEscalation: false\n            capabilities: { drop: [\"ALL\"] }\n---\napiVersion: v1\nkind: Service\nmetadata:\n  name: web\nspec:\n  selector: { app: web }\n  ports:\n    - { name: http, port: 80, targetPort: http }"}]}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Service type"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Reachable from"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"When"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"ClusterIP","marks":[{"type":"code"}]},{"type":"text","text":" (default)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"inside the cluster"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"service-to-service traffic – all our Services"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"NodePort","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"a port on every node"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"testing, older integrations"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"LoadBalancer","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"an external cloud load balancer"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"a single TCP/UDP service exposed to the world"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Gateway API / Ingress"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"one HTTP(S) entry point with routing"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"many HTTP services under one domain, TLS"}]}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"Kubernetes has two APIs for external HTTP traffic. "},{"type":"text","text":"Ingress","marks":[{"type":"bold"}]},{"type":"text","text":" is older and simpler, and its most popular controller, ingress-nginx, was retired in March 2026 (no new releases or security fixes). Its successor is the "},{"type":"text","text":"Gateway API","marks":[{"type":"bold"}]},{"type":"text","text":": roles are separated (the platform team manages the "},{"type":"text","text":"Gateway","marks":[{"type":"code"}]},{"type":"text","text":", application teams manage their "},{"type":"text","text":"HTTPRoute","marks":[{"type":"code"}]},{"type":"text","text":"s), and routing, headers and traffic splitting are part of the standard instead of controller-specific annotations."}]},{"type":"codeGroup","attrs":{"title":"Gateway API (recommended) and Ingress (alternative)"},"content":[{"type":"codeBlock","attrs":{"language":"yaml","filename":"k8s/gateway.yaml"},"content":[{"type":"text","text":"# Gateway API – the successor of Ingress (ingress-nginx was retired in March 2026).\n# Requires a Gateway controller (Envoy Gateway, NGINX Gateway Fabric, Cilium, Istio, cloud LBs…).\napiVersion: gateway.networking.k8s.io/v1\nkind: Gateway\nmetadata:\n  name: pierogi\nspec:\n  gatewayClassName: eg # name of the GatewayClass installed by your controller\n  listeners:\n    - name: http\n      protocol: HTTP\n      port: 80\n      hostname: pierogi.localtest.me\n---\napiVersion: gateway.networking.k8s.io/v1\nkind: HTTPRoute\nmetadata:\n  name: pierogi\nspec:\n  parentRefs:\n    - name: pierogi\n  hostnames: [\"pierogi.localtest.me\"]\n  rules:\n    - matches:\n        - path: { type: PathPrefix, value: /api }\n      backendRefs:\n        - { name: api, port: 3000 }\n    - matches:\n        - path: { type: PathPrefix, value: / }\n      backendRefs:\n        - { name: web, port: 80 }"}]},{"type":"codeBlock","attrs":{"language":"yaml","filename":"k8s/ingress.yaml"},"content":[{"type":"text","text":"# The classic Ingress API still works and is supported by many controllers\n# (Traefik, HAProxy, cloud load balancers). Pick ONE: gateway.yaml or ingress.yaml.\napiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n  name: pierogi\nspec:\n  ingressClassName: traefik\n  rules:\n    - host: pierogi.localtest.me\n      http:\n        paths:\n          - path: /api\n            pathType: Prefix\n            backend:\n              service: { name: api, port: { number: 3000 } }\n          - path: /\n            pathType: Prefix\n            backend:\n              service: { name: web, port: { number: 80 } }"}]}]},{"type":"paragraph","content":[{"type":"text","text":"Both variants need an installed controller (e.g. Envoy Gateway, NGINX Gateway Fabric, Cilium, Traefik or a cloud load balancer controller). Locally, without a controller, a port forward is enough:"}]},{"type":"output","attrs":{"title":"kubectl port-forward and a request through the frontend (sample output)","language":"bash","content":"$ kubectl -n pierogi port-forward service/web 8080:80\nForwarding from 127.0.0.1:8080 -> 8080\nForwarding from [::1]:8080 -> 8080\n\n$ curl -s localhost:8080/api/menu\n{\"source\":\"database\",\"items\":[{\"id\":\"ruskie\",\"name\":\"Ruskie\",\"price_cents\":2400},{\"id\":\"spinach\",\"name\":\"Spinach & feta\",\"price_cents\":2600},{\"id\":\"meat\",\"name\":\"With meat\",\"price_cents\":2700}]}"}},{"type":"heading","attrs":{"level":2,"id":"step-6-rolling-update-and-rollback"},"content":[{"type":"text","text":"Step 6. Rolling update and rollback"}]},{"type":"paragraph","content":[{"type":"text","text":"Changing the image in a Deployment creates a new ReplicaSet. With "},{"type":"text","text":"maxSurge: 1","marks":[{"type":"code"}]},{"type":"text","text":" and "},{"type":"text","text":"maxUnavailable: 0","marks":[{"type":"code"}]},{"type":"text","text":", Kubernetes adds one new pod, waits for it to pass readiness, removes one old pod – and repeats until done. The number of ready replicas never drops below two."}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"sequenceDiagram\n  participant D as Deployment\n  participant Old as ReplicaSet v1.0.0\n  participant New as ReplicaSet v1.1.0\n  participant S as Service api\n  D->>New: scale to 1 (3 pods in total)\n  New-->>S: v1.1.0 pod ready (readiness OK) – receives traffic\n  D->>Old: scale to 1\n  Old-->>S: preStop sleep 5, SIGTERM, pod removed from endpoints\n  D->>New: scale to 2\n  New-->>S: second pod ready\n  D->>Old: scale to 0","caption":"API rolling update: maxSurge 1, maxUnavailable 0"}},{"type":"output","attrs":{"title":"kubectl: update, history and rollback (sample output)","language":"bash","content":"$ kubectl -n pierogi set image deployment/api api=pierogi-api:1.1.0\ndeployment.apps/api image updated\n\n$ kubectl -n pierogi rollout status deployment/api\nWaiting for deployment \"api\" rollout to finish: 1 out of 2 new replicas have been updated...\nWaiting for deployment \"api\" rollout to finish: 1 old replicas are pending termination...\ndeployment \"api\" successfully rolled out\n\n$ kubectl -n pierogi rollout history deployment/api\ndeployment.apps/api\nREVISION  CHANGE-CAUSE\n1         <none>\n2         <none>\n\n$ kubectl -n pierogi rollout undo deployment/api\ndeployment.apps/api rolled back"}},{"type":"paragraph","content":[{"type":"text","text":"If the new version fails readiness (e.g. a configuration error), the update stalls: the old pods keep serving traffic, and after "},{"type":"text","text":"progressDeadlineSeconds","marks":[{"type":"code"}]},{"type":"text","text":" (600 s by default) "},{"type":"text","text":"rollout status","marks":[{"type":"code"}]},{"type":"text","text":" reports an error. Then it is "},{"type":"text","text":"rollout undo","marks":[{"type":"code"}]},{"type":"text","text":" – or a fix and another deployment."}]},{"type":"heading","attrs":{"level":2,"id":"step-7-hpa-autoscaling"},"content":[{"type":"text","text":"Step 7. HPA autoscaling"}]},{"type":"codeGroup","attrs":{"title":"HorizontalPodAutoscaler for the API"},"content":[{"type":"codeBlock","attrs":{"language":"yaml","filename":"k8s/hpa.yaml"},"content":[{"type":"text","text":"apiVersion: autoscaling/v2\nkind: HorizontalPodAutoscaler\nmetadata:\n  name: api\nspec:\n  scaleTargetRef:\n    apiVersion: apps/v1\n    kind: Deployment\n    name: api\n  minReplicas: 2\n  maxReplicas: 10\n  metrics:\n    - type: Resource\n      resource:\n        name: cpu\n        target:\n          type: Utilization # % of the CPU *request* (100m) – no requests, no autoscaling\n          averageUtilization: 70\n  behavior:\n    scaleDown:\n      stabilizationWindowSeconds: 300 # wait 5 min before removing pods (no flapping)"}]}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"flowchart LR\n  MS[\"metrics-server<br/>pod CPU usage\"] --> HPA[\"HPA<br/>desired = ⌈current × usage / target⌉\"]\n  HPA -->|\"change replicas\"| DEP[\"Deployment api\"]\n  DEP --> PODS[\"api pods\"]\n  PODS -->|\"kubelet reports usage\"| MS","caption":"The HPA loop (every 15 s)"}},{"type":"paragraph","content":[{"type":"text","text":"Every 15 seconds the HPA fetches CPU usage from metrics-server and computes the replica count: with 2 replicas averaging 188% of their request and a 70% target, it gets ⌈2 × 188 / 70⌉ = 6. Scaling up is fast, while scaling down waits 5 minutes ("},{"type":"text","text":"stabilizationWindowSeconds: 300","marks":[{"type":"code"}]},{"type":"text","text":") so the pod count does not jump on brief traffic dips."}]},{"type":"output","attrs":{"title":"kubectl get hpa during a load test (sample output)","language":"bash","content":"$ kubectl -n pierogi get hpa api --watch\nNAME   REFERENCE        TARGETS         MINPODS   MAXPODS   REPLICAS   AGE\napi    Deployment/api   cpu: 4%/70%     2         10        2          9m\napi    Deployment/api   cpu: 188%/70%   2         10        2          11m\napi    Deployment/api   cpu: 188%/70%   2         10        6          11m\napi    Deployment/api   cpu: 64%/70%    2         10        6          12m"}},{"type":"paragraph","content":[{"type":"text","text":"The HPA does not work without two things: an installed metrics-server (kind needs it added, minikube has a "},{"type":"text","text":"metrics-server","marks":[{"type":"code"}]},{"type":"text","text":" addon) and CPU requests on the container – the percentage is computed against the request. For queue workers it is better to scale on queue length (KEDA), and the node count is grown by a separate autoscaler – both are covered in the "},{"type":"text","text":"production tutorial","marks":[{"type":"link","attrs":{"href":"/en/articles/kubernetes-production"}}]},{"type":"text","text":"."}]},{"type":"heading","attrs":{"level":2,"id":"debugging-where-to-start"},"content":[{"type":"text","text":"Debugging: where to start"}]},{"type":"codeBlock","attrs":{"language":"bash"},"content":[{"type":"text","text":"kubectl -n pierogi get pods -o wide                   # status, restarts, node\nkubectl -n pierogi describe pod <pod>                 # events: image pull, probes, OOMKilled\nkubectl -n pierogi logs deploy/api --previous         # logs of the previous (restarted) container\nkubectl -n pierogi get events --sort-by=.lastTimestamp\nkubectl -n pierogi exec -it deploy/api -- sh          # only if the image has a shell"}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Status"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Most common cause"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Pending","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"no node with free resources (requests too big) or no volume"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"ImagePullBackOff","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"a typo in the image name, no registry access, image not loaded into a local cluster"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"CrashLoopBackOff","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the app exits at startup – check "},{"type":"text","text":"logs --previous","marks":[{"type":"code"}]},{"type":"text","text":" and environment variables"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"OOMKilled","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the memory limit was exceeded – measure usage and fix the limit or the leak"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Running","marks":[{"type":"code"}]},{"type":"text","text":" but "},{"type":"text","text":"0/1","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"readiness fails – a dependency (database, Redis) or a wrong probe path"}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"common-mistakes"},"content":[{"type":"text","text":"Common mistakes"}]},{"type":"callout","attrs":{"variant":"danger","title":"`latest` and `imagePullPolicy: Always` as a deployment strategy"},"content":[{"type":"paragraph","content":[{"type":"text","text":"The "},{"type":"text","text":"latest","marks":[{"type":"code"}]},{"type":"text","text":" tag does not tell you which version is running, and \"deploying\" by deleting pods so they pull a new image bypasses the rolling update and the history. Every version gets its own tag (or digest), and changing the tag in the manifest is a deployment that can be rolled back."}]}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Liveness depending on the database","marks":[{"type":"bold"}]},{"type":"text","text":" – a database outage restarts every pod."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"No requests","marks":[{"type":"bold"}]},{"type":"text","text":" – the scheduler crams pods onto one node, the HPA does not work, and "},{"type":"text","text":"BestEffort","marks":[{"type":"code"}]},{"type":"text","text":" pods die first when memory runs out."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Passwords in a ConfigMap, or a Secret in the repository","marks":[{"type":"bold"}]},{"type":"text","text":" – a Secret is base64, not encryption."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"One replica \"because it's just an API\"","marks":[{"type":"bold"}]},{"type":"text","text":" – every node upgrade or restart means downtime."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"kubectl edit","marks":[{"type":"code"}]},{"type":"text","text":" on a live cluster","marks":[{"type":"bold"}]},{"type":"text","text":" – a change that is not in the repository disappears at the next "},{"type":"text","text":"apply","marks":[{"type":"code"}]},{"type":"text","text":". Manifests are the source of truth."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"A Service selector that does not match pod labels","marks":[{"type":"bold"}]},{"type":"text","text":" – a Service without endpoints, and timeouts. Check "},{"type":"text","text":"kubectl get endpointslices -l kubernetes.io/service-name=api","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]}]},{"type":"heading","attrs":{"level":2,"id":"check-yourself"},"content":[{"type":"text","text":"Check yourself"}]},{"type":"quiz","attrs":{"question":"The database has a 2-minute outage. The API has a readiness probe that checks the database and a liveness probe that checks only the process. What happens?","multiple":false,"options":[{"text":"Kubernetes restarts every API pod","correct":false,"explanation":"Restarts are triggered by liveness, which does not check the database."},{"text":"The API pods stop receiving traffic (0/1 READY) but are not restarted, and return to traffic once the database answers","correct":true,"explanation":"Yes. Readiness controls membership in the Service endpoints, liveness controls restarts."},{"text":"The Deployment rolls back to the previous version","correct":false,"explanation":"Kubernetes does not roll back deployments automatically because of probes."}]}},{"type":"quiz","attrs":{"question":"The HPA shows `cpu: <unknown>/70%` and does not scale. What do you check first?","multiple":false,"options":[{"text":"Whether `maxReplicas` is greater than 10","correct":false,"explanation":"The replica limit does not affect reading metrics."},{"text":"Whether metrics-server is running and the container has a CPU request","correct":true,"explanation":"Yes. Without metrics or without a request the HPA has nothing to compute a percentage from."},{"text":"Whether the Service is of type LoadBalancer","correct":false,"explanation":"The Service type is irrelevant to the HPA."}]}},{"type":"details","content":[{"type":"detailsSummary","content":[{"type":"text","text":"Interview question: \"How do liveness, readiness and startup probes differ, and how would you configure them for an API?\""}]},{"type":"detailsContent","content":[{"type":"paragraph","content":[{"type":"text","text":"Readiness answers whether the pod can serve traffic right now – on failure the pod leaves the Service endpoints but is not restarted; it checks the dependencies needed to handle requests (database, cache). Liveness answers whether the process is stuck – on failure the kubelet restarts the container; it checks only the process itself, never external dependencies, because a database outage would restart every replica. Startup protects slow-starting apps: until it passes, liveness and readiness are not run. For a NestJS API: startup and liveness on a lightweight "},{"type":"text","text":"/live","marks":[{"type":"code"}]},{"type":"text","text":", readiness on "},{"type":"text","text":"/health","marks":[{"type":"code"}]},{"type":"text","text":" with the database and Redis, a short "},{"type":"text","text":"periodSeconds","marks":[{"type":"code"}]},{"type":"text","text":" for readiness and a gentler one for liveness. Plus a "},{"type":"text","text":"preStop","marks":[{"type":"code"}]},{"type":"text","text":" with a short wait and "},{"type":"text","text":"SIGTERM","marks":[{"type":"code"}]},{"type":"text","text":" handling, so rolling updates happen without 502 errors."}]}]}]},{"type":"heading","attrs":{"level":2,"id":"what-next"},"content":[{"type":"text","text":"What next"}]},{"type":"linkCard","attrs":{"url":"/en/articles/kubernetes-production","title":"Kubernetes in production","description":"Helm, RBAC, NetworkPolicy, PDB, KEDA, observability and GitOps","kind":"article","ref":"kubernetes-production"}},{"type":"linkCard","attrs":{"url":"/en/articles/docker-for-developers","title":"Docker for developers","description":"The images we deploy here: multi-stage, small and rootless","kind":"article","ref":"docker-for-developers"}},{"type":"linkCard","attrs":{"url":"/en/articles/nestjs-microservices","title":"Microservices in NestJS","description":"More services to run in the cluster","kind":"article","ref":"nestjs-microservices"}},{"type":"linkCard","attrs":{"url":"/en/topics/microservices","title":"Microservices","description":"When splitting into services makes sense","kind":"topic","ref":"microservices"}}]},"toc":[{"id":"how-a-cluster-is-built","text":"How a cluster is built","level":2,"locked":false},{"id":"step-1-a-local-cluster-and-images","text":"Step 1. A local cluster and images","level":2,"locked":false},{"id":"step-2-namespace-configuration-and-a-secret","text":"Step 2. Namespace, configuration and a secret","level":2,"locked":false},{"id":"step-3-data-postgresql-as-a-statefulset-and-redis","text":"Step 3. Data: PostgreSQL as a StatefulSet, and Redis","level":2,"locked":false},{"id":"step-4-api-a-deployment-with-probes-resources-and-a-hardened-security-context","text":"Step 4. API: a Deployment with probes, resources and a hardened security context","level":2,"locked":false},{"id":"three-probes-three-questions","text":"Three probes, three questions","level":3,"locked":false},{"id":"requests-limits-and-qos-classes","text":"Requests, limits and QoS classes","level":3,"locked":false},{"id":"other-details-of-the-manifest","text":"Other details of the manifest","level":3,"locked":false},{"id":"step-5-the-frontend-and-traffic-from-outside","text":"Step 5. The frontend and traffic from outside","level":2,"locked":false},{"id":"step-6-rolling-update-and-rollback","text":"Step 6. Rolling update and rollback","level":2,"locked":false},{"id":"step-7-hpa-autoscaling","text":"Step 7. HPA autoscaling","level":2,"locked":false},{"id":"debugging-where-to-start","text":"Debugging: where to start","level":2,"locked":false},{"id":"common-mistakes","text":"Common mistakes","level":2,"locked":false},{"id":"check-yourself","text":"Check yourself","level":2,"locked":false},{"id":"what-next","text":"What next","level":2,"locked":false}],"locked":false,"paywall":null,"previewRatio":0.3,"totalBlocks":62,"visibleBlocks":62,"resources":[{"id":"6b0857c43c96f2d34d0b46ab","type":"book","provider":"openlibrary","url":"https://openlibrary.org/works/OL21338519W","embedUrl":null,"title":"Kubernetes Patterns","description":"","author":"Bilgin Ibryam, Roland Huß","thumbnailUrl":"https://covers.openlibrary.org/b/id/15273476-L.jpg","durationSec":null,"lang":"en","topics":[],"techs":["general"],"tags":["book","cloud","kubernetes"],"price":"paid","featured":false,"featuredOrder":0,"packageName":null,"source":"openlibrary","publishedAt":"2019-01-01T00:00:00.000Z","popularity":44,"verifiedAt":"2026-11-26T11:00:08.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:07.480Z","updatedAt":"2026-11-26T16:01:07.480Z"},{"id":"6b0857bd3c96f2d34d0b4180","type":"podcast","provider":"apple-podcasts","url":"https://podcasts.apple.com/pl/podcast/008-jak-zacz%C4%85%C4%87-wdra%C5%BCa%C4%87-aplikacje-w-kubernetes/id1545962394?i=1000536714434","embedUrl":"https://embed.podcasts.apple.com/us/podcast/id1545962394?i=1000536714434","title":"008: Jak zacząć wdrażać aplikacje w Kubernetes?","description":"Hej! Czas na kolejny odcinek podcastu. Tym razem opowiadam w nim o moim projekcie — Kubernetes Maestro. Jest to projekt, nad którym pracowałem przez ostatnie pół roku. Projekt, który pochłonął bardzo dużo mojego czasu i energii. Aczkolwiek wyszła petarda (szczegóły w odcinku). Wszystkie szczegóły…","author":"Damian Naprawa Podcast (AI x DevOps)","thumbnailUrl":"https://is1-ssl.mzstatic.com/image/thumb/Podcasts126/v4/ca/f5/8a/caf58a9f-f12b-9084-7db2-a5cbba59e807/mza_8754745953681324003.jpg/600x600bb.jpg","durationSec":643,"lang":"pl","topics":[],"techs":["general"],"tags":["podcast","kubernetes"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"itunes","publishedAt":"2021-09-27T07:05:55.000Z","popularity":30,"verifiedAt":"2026-11-26T11:08:22.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:59.965Z","updatedAt":"2026-11-26T16:00:59.965Z"},{"id":"6b0857b23c96f2d34d0b350f","type":"repo","provider":"github","url":"https://github.com/stefanprodan/podinfo","embedUrl":null,"title":"stefanprodan/podinfo","description":"Go microservice template for Kubernetes","author":"stefanprodan","thumbnailUrl":"https://opengraph.githubassets.com/1/stefanprodan/podinfo","durationSec":null,"lang":"en","topics":["microservices"],"techs":["go"],"tags":["cuelang","e2e-testing","gitops","golang","helm","kubernetes","testing","kustomize","microservice","software-architecture"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"github","publishedAt":"2018-01-05T14:19:59.000Z","popularity":73,"verifiedAt":"2026-11-26T10:58:37.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:50.215Z","updatedAt":"2026-11-26T16:00:50.215Z"},{"id":"6b0857bf3c96f2d34d0b4255","type":"article","provider":"web","url":"https://learn.microsoft.com/en-us/azure/architecture/microservices/design/orchestration","embedUrl":null,"title":"Container orchestration for microservices","description":"Learn how container orchestration makes it easy to manage complex multi-container microservice deployments, scaling, and cluster health.","author":"Microsoft Azure Architecture Center","thumbnailUrl":"https://learn.microsoft.com/en-us/media/open-graph-image.png","durationSec":null,"lang":"en","topics":["microservices"],"techs":["general"],"tags":["azure","cloud","software-architecture"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":67,"verifiedAt":"2026-11-26T11:07:37.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"},{"id":"6b0857b73c96f2d34d0b3c52","type":"podcast","provider":"apple-podcasts","url":"https://podcasts.apple.com/us/podcast/kelsey-hightower-on-extending-kubernetes-event-driven/id1106971805?i=1000462112142","embedUrl":"https://embed.podcasts.apple.com/us/podcast/id1106971805?i=1000462112142","title":"Kelsey Hightower on Extending Kubernetes, Event-Driven Architecture, and Learning","description":"In this podcast, Daniel Bryant sat down with Kelsey Hightower, Staff Developer Advocate at Google. Topics covered included: the extensibility of Kubernetes, and why it has become the platform that other platforms are being built on top of; creating event-driven architectures and deploying these…","author":"The InfoQ Podcast","thumbnailUrl":"https://is1-ssl.mzstatic.com/image/thumb/Podcasts115/v4/03/b2/02/03b20296-6a78-d2c9-1bf9-24ac3c090b97/mza_12133700838328477375.jpg/600x600bb.jpg","durationSec":1579,"lang":"en","topics":["event-driven-architecture"],"techs":["general"],"tags":["podcast","software-architecture","cloud","kubernetes"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"itunes","publishedAt":"2020-01-10T12:31:53.000Z","popularity":64,"verifiedAt":"2026-11-26T10:58:56.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:53.924Z","updatedAt":"2026-11-26T16:00:53.924Z"}],"challenges":[{"id":"6b093dc291bd8fbaf2a0c8d8","slug":"payment-circuit-breaker","title":"Circuit breaker for a payment gateway","summary":"A circuit breaker with closed, open and half-open states, an injected clock, a trial-success threshold and a business-error filter – so a payment gateway outage does not take the whole shop down.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":"architecture","status":"published","difficulty":"hard","topics":["circuit-breaker","microservices"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["circuit-breaker","resilience","fault-tolerance","state-machine","payments"],"languages":["typescript","javascript","python","csharp","java","go"],"questionCount":null,"xp":40,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:26.251Z"}],"attachments":[],"hasCode":true,"repoUrl":null,"series":[],"prev":null,"next":null,"featured":false,"authorCard":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","headline":"Wzorce projektowe · Architektura · AI i LLM","community":false,"reputation":{"points":3900,"level":{"key":"mentor","label":"Mentor"}},"articles":104,"skills":[{"key":"typescript","title":"TypeScript","level":5,"levelLabel":"Authority","articles":90},{"key":"dotnet","title":".NET","level":5,"levelLabel":"Authority","articles":61},{"key":"python","title":"Python","level":5,"levelLabel":"Authority","articles":59},{"key":"java","title":"Java","level":5,"levelLabel":"Authority","articles":46}]}}