Skip to content
System design on Kubernetes · Chapter 3 of 20 Day 1: kurz as a Deployment

Day 1: kurz as a Deployment

Goal: Run PostgreSQL with CloudNativePG as a single instance, restore the 2.7 million old links and start kurz as a Deployment with Service, ConfigMap, Secret and probes · Duration: approx. 75 min · Prerequisite: Day 0

Briefing

  • In the predecessor course, kurz ran as a systemd service. Its configuration lived in a drop-in file, its health check in HAProxy, the database on s3. Today, each of these gets its Kubernetes form:
On the VM In the cluster
systemd unit with Restart=always Deployment with two replicas
Environment= in a drop-in file ConfigMap, and a Secret for the password
HAProxy option httpchk GET /readyz Readiness probe; the Service endpoints follow it
systemctl restart after an error Liveness probe; the kubelet restarts the container
PostgreSQL by hand on s3 CloudNativePG with one instance (replicas on Day 6)
DNS name s3 Service name db-rw
  • The most important lesson of the day lies in the difference between the two probes. You deliberately make the database unreachable and watch what each probe makes of it.

Drill 1: The operator

CloudNativePG (CNPG) is an operator: a controller in the cluster that understands its own resource called Cluster and turns it into PostgreSQL pods, volumes, Services, certificates and, later, replication and failover. You install it with its Helm chart:

# on s1
# Add the CloudNativePG Helm repository and update it
helm repo add cnpg https://cloudnative-pg.github.io/charts
helm repo update cnpg
# Which chart version ships which operator?
helm search repo cnpg/cloudnative-pg
# Install the operator into its own namespace, fixed version
helm install cnpg cnpg/cloudnative-pg -n cnpg-system --create-namespace --version 0.29.2
# Wait until it is running
kubectl -n cnpg-system rollout status deploy/cnpg-cloudnative-pg
# Pod and node of the operator
kubectl -n cnpg-system get pods -o wide

Expected (abridged):

NAME                CHART VERSION   APP VERSION DESCRIPTION
cnpg/cloudnative-pg 0.29.2          1.30.2      CloudNativePG Operator Helm Chart
STATUS: deployed
REVISION: 1
deployment "cnpg-cloudnative-pg" successfully rolled out
NAME                                   READY   STATUS    RESTARTS   AGE   IP          NODE
cnpg-cloudnative-pg-794486c67f-x9d8j   1/1     Running   0          22s   10.42.4.3   s3

Chart version 0.29.2 ships operator 1.30.2.

Happened during testing: CNPG also comes as a single YAML file (cnpg-1.30.2.yaml). If you apply it after the Helm chart is already installed, you get a second operator: the chart names its Deployment cnpg-cloudnative-pg, the YAML file cnpg-controller-manager. Shared objects such as webhooks fail with conflict with "helm"; the rest are created. Two operators managing the same clusters fight each other. Pick one way; this course uses Helm.

Save your progress? Sign up for free

Drill 2: A database with one instance

First a namespace for everything that belongs to kurz, and a Secret with user and password. CNPG expects the type kubernetes.io/basic-auth for it:

# on s1
# Working directory for today
mkdir -p ~/sdk/tag01 && cd ~/sdk/tag01
# Namespace for everything that belongs to kurz
kubectl create namespace kurz
# Database user and password as a Secret of type basic-auth
kubectl -n kurz create secret generic db-kurz --type=kubernetes.io/basic-auth \
  --from-literal=username=kurz --from-literal=password=lab-kurz-123

User and password are the same as in the predecessor course. Now the database:

# on s1
# Cluster resource: one instance, 5 GiB, database kurz with owner kurz from the Secret
cat > db.yaml <<EOF
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: db
  namespace: kurz
spec:
  instances: 1
  storage:
    size: 5Gi
  bootstrap:
    initdb:
      database: kurz
      owner: kurz
      secret:
        name: db-kurz
EOF
# Create it
kubectl apply -f db.yaml
# Wait until CNPG reports the cluster as ready
kubectl -n kurz wait --for=condition=Ready cluster/db --timeout=300s
# Which PostgreSQL image did CNPG choose?
kubectl -n kurz get cluster db -o jsonpath='{.status.image}{"\n"}'
# Pod, Services and volume the operator created
kubectl -n kurz get pods,svc,pvc -o wide

Expected (abridged):

cluster.postgresql.cnpg.io/db created
cluster.postgresql.cnpg.io/db condition met
ghcr.io/cloudnative-pg/postgresql:18.7-system-trixie
NAME       READY   STATUS    RESTARTS   AGE   IP          NODE
pod/db-1   1/1     Running   0          12s   10.42.0.8   s1

NAME            TYPE        CLUSTER-IP      PORT(S)    SELECTOR
service/db-r    ClusterIP   10.43.249.212   5432/TCP   cnpg.io/cluster=db,cnpg.io/podRole=instance
service/db-ro   ClusterIP   10.43.199.194   5432/TCP   cnpg.io/cluster=db,cnpg.io/instanceRole=replica
service/db-rw   ClusterIP   10.43.45.241    5432/TCP   cnpg.io/cluster=db,cnpg.io/instanceRole=primary

NAME                         STATUS   VOLUME                                     CAPACITY   STORAGECLASS
persistentvolumeclaim/db-1   Bound    pvc-40bff696-f296-4d42-9101-aafc13806231   5Gi        local-path

Without imageName, CNPG uses its default image, here PostgreSQL 18.7, the same version as in the predecessor course. Three Services appear on their own:

Service points to you need it
db-rw the primary today, for writing and reading
db-ro replicas only Day 6, read Service
db-r all instances rarely, for reads that may also use the primary

db-ro has no endpoints today because there is no replica yet. These three names replace the addresses s3:5432 and s3:6432 from the predecessor course, and they stay the same when the primary changes during a failover (Day 7).

Caution: The volume is local-path: a directory on exactly the node where db-1 is currently running. If that node fails, the data is gone until it returns. With one instance, that is a single point of failure. Days 6 and 7 solve this with replicas, not with different storage.

Save your progress? Sign up for free

Drill 3: Restoring the old data

The dump from Day 0 is in ~/sd-archiv/kurz.dump. Copy it into the pod and restore it with pg_restore. --no-owner --role=kurz makes the user kurz the owner of all tables, no matter whom they belonged to on the old VM:

# on s1
# Copy the backup into the pod's data directory
kubectl -n kurz cp ~/sd-archiv/kurz.dump db-1:/var/lib/postgresql/data/kurz.dump -c postgres
# Restore it, kurz becomes the owner of all objects; time measures the duration
time kubectl -n kurz exec db-1 -c postgres -- pg_restore -U postgres -d kurz --no-owner --role=kurz \
  /var/lib/postgresql/data/kurz.dump
# Did all links arrive?
kubectl -n kurz exec db-1 -c postgres -- psql -U postgres -d kurz -Atc "select count(*) from links"
# Tables and their owners
kubectl -n kurz exec db-1 -c postgres -- psql -U postgres -d kurz -c '\dt'
# Delete the backup in the pod again
kubectl -n kurz exec db-1 -c postgres -- rm /var/lib/postgresql/data/kurz.dump

Expected:

real    0m25.727s
2727215
               List of tables
 Schema |        Name        | Type  | Owner
--------+--------------------+-------+-------
 public | idempotenz         | table | kurz
 public | klicks             | table | kurz
 public | klicks_verarbeitet | table | kurz
 public | links              | table | kurz
(4 rows)

26 seconds for 2.7 million links including indexes. The file goes into the data directory because the container’s file system has hardly any space otherwise; afterwards you delete it again.

Save your progress? Sign up for free

Drill 4: kurz as a Deployment

kurz reads its settings from environment variables (KURZ_DB, KURZ_TIMEOUT …). In the cluster, they come from three sources: a ConfigMap for the non-sensitive ones, a Secret for the password, and the Downward API for the pod name, which kurz writes into every response as X-Kurz-Instanz.

# on s1
# ConfigMap, Deployment and Service in one file; the quoted 'EOF' leaves $(…) untouched
cat > kurz.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
  name: kurz
  namespace: kurz
data:
  KURZ_TIMEOUT: "2s"
  KURZ_CODELAENGE: "7"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kurz
  namespace: kurz
spec:
  replicas: 2
  selector:
    matchLabels:
      app: kurz
  template:
    metadata:
      labels:
        app: kurz
    spec:
      containers:
      - name: kurz
        image: 172.16.0.126:5000/kurz:1.0
        ports:
        - name: http
          containerPort: 8080
        envFrom:
        - configMapRef:
            name: kurz
        env:
        - name: KURZ_INSTANZ
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: DB_PASSWORT
          valueFrom:
            secretKeyRef:
              name: db-kurz
              key: password
        - name: KURZ_DB
          value: postgres://kurz:$(DB_PASSWORT)@db-rw:5432/kurz
        livenessProbe:
          httpGet:
            path: /healthz
            port: http
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /readyz
            port: http
          periodSeconds: 5
          failureThreshold: 2
        securityContext:
          allowPrivilegeEscalation: false
          readOnlyRootFilesystem: true
          runAsNonRoot: true
---
apiVersion: v1
kind: Service
metadata:
  name: kurz
  namespace: kurz
spec:
  selector:
    app: kurz
  ports:
  - name: http
    port: 80
    targetPort: http
EOF

Three spots deserve a second look:

  • $(DB_PASSWORT) is not shell. Kubernetes substitutes the value of a previously defined variable into a later one. That’s why DB_PASSWORT comes before KURZ_DB. The quoted 'EOF' prevents your own shell from executing $(…) while writing the file. If a password contains characters such as @ or /, the URL breaks; then it has to go into the Secret URL-encoded.
  • Two probes, two paths. /healthz always answers ok as long as the process is alive. /readyz checks cache and database, just as HAProxy did in the predecessor course.
  • readOnlyRootFilesystem: kurz writes nothing to disk, so it isn’t allowed to either.
# on s1
# Create all three objects
kubectl apply -f kurz.yaml
# State of the kurz pods
kubectl -n kurz get pods -l app=kurz

Expected:

configmap/kurz created
deployment.apps/kurz created
service/kurz created
NAME                    READY   STATUS                       RESTARTS   AGE
kurz-7f6868f8b6-bb9cs   0/1     CreateContainerConfigError   0          2m4s
kurz-7f6868f8b6-kzstp   0/1     CreateContainerConfigError   0          2m4s

No crash; the container isn’t even created. The events say why:

# on s1
# Events with reason Failed, each message only once
kubectl -n kurz get events --field-selector reason=Failed -o custom-columns=MELDUNG:.message --no-headers | sort -u

Expected (abridged):

Error: container has runAsNonRoot and image has non-numeric user (nonroot), cannot verify user is non-root

The distroless image sets USER nonroot, a name. From a name, the kubelet cannot tell whether UID 0 is behind it, so it refuses to start. The fix: state the UID explicitly. With distroless, nonroot is always 65532.

# on s1
# Insert the numeric UID 65532 after runAsNonRoot
sed -i 's/          runAsNonRoot: true/          runAsNonRoot: true\n          runAsUser: 65532/' kurz.yaml
# Apply and wait until both pods are ready
kubectl apply -f kurz.yaml
kubectl -n kurz rollout status deploy/kurz
# Pods with IP and node
kubectl -n kurz get pods -l app=kurz -o wide
# Startup messages of both pods, prefixed with the pod name
kubectl -n kurz logs -l app=kurz --prefix

Expected (abridged):

deployment "kurz" successfully rolled out
NAME                   READY   STATUS    RESTARTS   AGE   IP          NODE
kurz-584fcf44d-5fq5p   1/1     Running   0          3s    10.42.2.8   s2
kurz-584fcf44d-7dd75   1/1     Running   0          5s    10.42.4.4   s3
[pod/kurz-584fcf44d-5fq5p/kurz] 2026/11/24 22:06:38 kurz-584fcf44d-5fq5p: 1 Shard(s)
[pod/kurz-584fcf44d-5fq5p/kurz] 2026/11/24 22:06:38 kurz-584fcf44d-5fq5p lauscht auf :8080
[pod/kurz-584fcf44d-7dd75/kurz] 2026/11/24 22:06:37 kurz-584fcf44d-7dd75: 1 Shard(s)
[pod/kurz-584fcf44d-7dd75/kurz] 2026/11/24 22:06:37 kurz-584fcf44d-7dd75 lauscht auf :8080

The instance names are now pod names, thanks to the Downward API. (lauscht auf is kurz’s German log message for “listening on”.)

Save your progress? Sign up for free

Drill 5: Through the Service

A Service of type ClusterIP has a virtual address that works on every node, including directly on s1:

# on s1
# Remember and show the ClusterIP of the Service
IP=$(kubectl -n kurz get svc kurz -o jsonpath='{.spec.clusterIP}'); echo $IP
# Create a link
curl -s -XPOST http://$IP/api/links -d '{"url":"https://itdrills.com/books/system-design-kubernetes"}'
# The same URL once more, remember only the code
C=$(curl -s -XPOST http://$IP/api/links -d '{"url":"https://itdrills.com/books/system-design-kubernetes"}' | jq -r .code)
# Redirect: status, target and answering pod
curl -si http://$IP/$C | grep -E "HTTP|Location|X-Kurz"
# Ten requests, counted by answering pod
for i in $(seq 1 10); do curl -s -o /dev/null -D - http://$IP/healthz | grep X-Kurz; done | sort | uniq -c

Expected (code and distribution differ):

10.43.67.150
{"code":"fcdCsEH","url":"https://itdrills.com/books/system-design-kubernetes"}
HTTP/1.1 302 Found
Location: https://itdrills.com/books/system-design-kubernetes
X-Kurz-Instanz: kurz-584fcf44d-7dd75
      4 X-Kurz-Instanz: kurz-584fcf44d-5fq5p
      6 X-Kurz-Instanz: kurz-584fcf44d-7dd75

The second POST with the same URL returns the same code: the behavior from the predecessor course remains. The 4:6 distribution is not round robin as with HAProxy; kube-proxy picks randomly per connection. And the old links?

# on s1
# Fetch the oldest code from the database
ALT=$(kubectl -n kurz exec db-1 -c postgres -- psql -d kurz -Atc "select code from links order by angelegt limit 1")
# Status and target of its redirect
curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" http://$IP/$ALT

Expected:

302 https://kubernetes.io/docs/

The oldest link from the predecessor course redirects. Pods in the cluster reach kurz by its DNS name:

# on s1
# Throwaway pod in namespace kurz queries the Service by its DNS name
kubectl -n kurz run dnstest --image=busybox:1.37 --restart=Never --rm -i -- wget -qSO /dev/null http://kurz/healthz

Expected (beginning):

  HTTP/1.1 200 OK
  X-Kurz-Instanz: kurz-8df6f8fb-kz7hh

Save your progress? Sign up for free

Drill 6: Liveness versus readiness

Now the database disappears. CNPG can send a cluster into hibernation: the pods go away, the volume stays. Open a second terminal and watch, every five seconds, the response for the old link, READY/RESTARTS of both kurz pods and the state of db-1:

# Terminal 2, on s1
# Look up the ClusterIP again in this shell
IP=$(kubectl -n kurz get svc kurz -o jsonpath='{.spec.clusterIP}')
# Every 5 s: HTTP status of the old link, READY/RESTARTS of both pods, state of db-1
while true; do
  echo "$(date +%T) $(curl -s -o /dev/null -w '%{http_code}' -m 3 http://$IP/MPKfz5D)" \
    "$(kubectl -n kurz get pods -l app=kurz --no-headers | awk '{printf "%s/%s ", $2, $4}')" \
    "db:$(kubectl -n kurz get pods -l cnpg.io/cluster=db --no-headers 2>/dev/null | awk '{print $3}')"
  sleep 5
done

Instead of MPKfz5D, use your $ALT. Then, in the first terminal:

# on s1
# Send the database into hibernation: pods go away, the volume stays
kubectl -n kurz annotate cluster db --overwrite cnpg.io/hibernation=on

Expected in terminal 2 (abridged):

22:07:03 302 1/1/0 1/1/0  db:Terminating
22:07:09 302 1/1/0 1/1/0  db:Terminating
…
22:10:02 302 1/1/0 1/1/0  db:Terminating
22:10:08 503 1/1/0 1/1/0  db:
22:10:14 503 1/1/0 0/1/0  db:
22:10:20 000 0/1/0 0/1/0  db:
22:10:26 000 0/1/0 0/1/0  db:

Three observations:

  1. Three minutes of Terminating. CNPG first shuts PostgreSQL down “smart”: it waits until all clients close their connections. But the two kurz pods each hold a pool of open connections and never close it. After the default period of 180 seconds (smartShutdownTimeout), CNPG switches to a fast shutdown. Until then, kurz keeps serving without errors.
  2. 503, then 000. As soon as the database is gone, kurz answers with 503. Ten seconds later (periodSeconds: 5 × failureThreshold: 2), both pods are 0/1, and the Service has no ready endpoints left: curl gets no connection at all (000).
  3. RESTARTS stays 0. The liveness probe asks /healthz, and that doesn’t depend on the database. The kubelet has no reason to restart kurz, and that is correct: a restart doesn’t repair a missing database.
# on s1
# Endpoints of the Service kurz with their ready state
kubectl -n kurz get endpointslices -l kubernetes.io/service-name=kurz \
  -o jsonpath='{range .items[*].endpoints[*]}{.addresses[0]} ready={.conditions.ready}{"\n"}{end}'
# The latest messages of failed probes
kubectl -n kurz get events --field-selector reason=Unhealthy -o custom-columns=MELDUNG:.message --no-headers | tail -2

Expected (abridged):

10.42.4.4 ready=false
10.42.2.8 ready=false
Readiness probe failed: Get "http://10.42.4.4:8080/readyz": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

The endpoints stay in the EndpointSlice, but with ready=false. And the probe doesn’t fail on a 503 but on a timeout: /readyz internally gives the database one second, and the probe’s timeoutSeconds is at its default, also one second. The probe gives up before kurz can answer. The result is the same, but the error message is misleading. Give the probe more time than the check behind it:

# on s1
# Insert timeoutSeconds: 2 two lines after "path: /readyz"
sed -i '/path: \/readyz/{n;n;s/          periodSeconds: 5/          periodSeconds: 5\n          timeoutSeconds: 2/}' kurz.yaml
# Check the readiness probe
grep -A6 readinessProbe kurz.yaml

Expected:

        readinessProbe:
          httpGet:
            path: /readyz
            port: http
          periodSeconds: 5
          timeoutSeconds: 2
          failureThreshold: 2

Wake the database, apply the change:

# on s1
# End hibernation and wait until the database is ready
kubectl -n kurz annotate cluster db --overwrite cnpg.io/hibernation=off
kubectl -n kurz wait --for=condition=Ready cluster/db --timeout=300s
# Roll out the new probe setting
kubectl apply -f kurz.yaml
kubectl -n kurz rollout status deploy/kurz
# Does the old link redirect again?
curl -s -o /dev/null -w "%{http_code}\n" http://$IP/$ALT

Expected (abridged):

cluster.postgresql.cnpg.io/db annotated
cluster.postgresql.cnpg.io/db condition met
deployment "kurz" successfully rolled out
302

Twelve seconds until Ready, and kurz serves again without a single restart.

Save your progress? Sign up for free

Drill 7: A rollout that gets stuck

What happens when new pods can’t reach the database but the old ones can? A NetworkPolicy blocks all incoming traffic to db-1. k3s enforces NetworkPolicies with its built-in controller:

# on s1
# NetworkPolicy without ingress rules: nobody may reach the pods of cluster db
cat > sperre.yaml <<EOF
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: db-sperre
  namespace: kurz
spec:
  podSelector:
    matchLabels:
      cnpg.io/cluster: db
  policyTypes: [Ingress]
EOF
# Create the block
kubectl apply -f sperre.yaml
# Roll out new kurz pods
kubectl -n kurz rollout restart deploy/kurz
# Give the rollout time
sleep 20
# Old and new pods
kubectl -n kurz get pods -l app=kurz
# Last log line of each pod
kubectl -n kurz logs -l app=kurz --tail=1 --prefix

Expected (abridged):

NAME                    READY   STATUS             RESTARTS     AGE
kurz-7b6568fd95-44v5s   1/1     Running            0            38s
kurz-7b6568fd95-fjxgt   1/1     Running            0            40s
kurz-8df6f8fb-nt86c     0/1     CrashLoopBackOff   2 (8s ago)   21s
[pod/kurz-8df6f8fb-nt86c/kurz]  10.43.45.241:5432 (db-rw): dial error: dial tcp 10.43.45.241:5432: connect: connection refused

The new pod crashes at startup: on startup, kurz creates the table links if it is missing, and exits if it can’t. The two old pods keep running, 1/1. Their connections existed before the block, and the policy only affects new ones. The rollout gets stuck because the default strategy (maxUnavailable: 25 %, rounded down to zero with two replicas) removes no old pod as long as no new one is ready. That way, a broken release doesn’t take the service down.

# on s1
# Remove the block
kubectl delete -f sperre.yaml
# Let the rollout finish
kubectl -n kurz rollout status deploy/kurz
# Pods afterwards
kubectl -n kurz get pods -l app=kurz

Expected (abridged):

networkpolicy.networking.k8s.io "db-sperre" deleted from kurz namespace
deployment "kurz" successfully rolled out
kurz-8df6f8fb-kz7hh     1/1     Running     0             3s
kurz-8df6f8fb-nt86c     1/1     Running     3 (28s ago)   41s

As soon as the block is gone, the stuck pod starts on its next attempt, and the rollout runs to completion.

Save your progress? Sign up for free

Exercise: A wrong password

  1. Start a single pod with kurz:1.0 and KURZ_DB=postgres://kurz:falsch@db-rw:5432/kurz. What status does it have, and what is in the log?
  2. You change KURZ_TIMEOUT in the ConfigMap to 1s. Do the running pods have the new value? How do you get it in?

Solution

# on s1
# 1: Single pod with a wrong password, no restart, as UID 65532
kubectl -n kurz run pwtest --image=172.16.0.126:5000/kurz:1.0 --restart=Never \
  --env=KURZ_DB=postgres://kurz:falsch@db-rw:5432/kurz \
  --overrides='{"spec":{"securityContext":{"runAsUser":65532}}}'
# Give kurz time to fail
sleep 8
# Last log line and status
kubectl -n kurz logs pwtest | tail -1
kubectl -n kurz get pod pwtest --no-headers
# Clean up
kubectl -n kurz delete pod pwtest

Expected:

2026/11/24 22:15:52 failed to connect to `user=kurz database=kurz`: 10.43.45.241:5432 (db-rw): failed SASL auth: FATAL: password authentication failed for user "kurz" (SQLSTATE 28P01)
pwtest   0/1   Error   0     9s

Error instead of CrashLoopBackOff, because --restart=Never allows no restart; in a Deployment it would be a loop. runAsUser is in the override so the test pod runs under the same UID as the real pods.

On 2: a process reads environment variables once at startup. A changed ConfigMap doesn’t reach running pods. Only a new pod sees it:

# on s1
# 2: Change the value in the ConfigMap
kubectl -n kurz patch configmap kurz --type merge -p '{"data":{"KURZ_TIMEOUT":"1s"}}'
# Force new pods that read the value at startup
kubectl -n kurz rollout restart deploy/kurz
# What rollout restart changed in the pod template
kubectl -n kurz get deploy kurz -o jsonpath='{.spec.template.metadata.annotations}{"\n"}'

Expected:

configmap/kurz patched
deployment.apps/kurz restarted
{"kubectl.kubernetes.io/restartedAt":"2026-11-24T22:14:31Z"}

rollout restart only changes an annotation in the pod template. That is enough for the Deployment to roll out new pods. Afterwards, set the value back to 2s and restart once more.

Save your progress? Sign up for free

Challenge

A colleague suggests: “Let the liveness probe ask /readyz too. Then Kubernetes notices when kurz loses the database and restarts it.” What happens in Drill 6 with this suggestion? Explain in three sentences, and name a case in which a liveness probe really helps.

Solution

After three failed liveness checks (default failureThreshold: 3), the kubelet restarts both pods, at the same time, and then again and again. Every restart fails at startup because of the missing database; the pods end up in CrashLoopBackOff with growing wait times of up to five minutes. When the database comes back, the pods may still be waiting in that pause instead of being ready again right away as in Drill 6. A failure of one dependency thus becomes a failure of the whole application; experts call this cascading failure.

Liveness makes sense when the process itself hangs: a deadlock, an infinite loop, a thread pool filling up. Then /healthz stops answering too, and a restart really helps.

Save your progress? Sign up for free

Checkpoint

# on s1
# Database with one instance, healthy
kubectl -n kurz get cluster db --no-headers | awk '{print $1, $3, $5, $6, $7, $8}'
# Two kurz pods ready
kubectl -n kurz get deploy kurz --no-headers | awk '{print $1, $2}'
# All old links present (t = true)
kubectl -n kurz exec db-1 -c postgres -- psql -d kurz -Atc "select count(*) >= 2727215 from links"
# kurz reports ready
curl -s http://$(kubectl -n kurz get svc kurz -o jsonpath='{.spec.clusterIP}')/readyz
# Readiness probe with a 2 s timeout
kubectl -n kurz get deploy kurz -o jsonpath='{.spec.template.spec.containers[0].readinessProbe.timeoutSeconds}{"\n"}'

Expected:

db 1 Cluster in healthy state
kurz 2/2
t
bereit
2

Interview note

  • Liveness or readiness? Readiness answers “should this pod receive requests right now?” and may check dependencies. Liveness answers “is this process broken and can only be saved by a restart?” and may only check the process itself. Mixing them up builds cascading failures.
  • Separate configuration and secrets: ConfigMap for values anyone may see, Secret for the rest. A Secret is base64, not encrypted; the protection comes from RBAC and encryption in etcd.

Enterprise note

  • A password created by hand with kubectl create secret is in no Git repo and cannot be rotated traceably. In production, it comes from a secret manager (External Secrets with OpenBao or Vault) or encrypted from Git (SOPS).
  • Database migrations don’t belong in the application’s startup. kurz creates links at startup, and Drill 7 shows the consequence: without a database, no pod starts. The usual way is a dedicated Job or an init container that migrates before the rollout.
  • CNPG can also manage users, databases and privileges declaratively (spec.managed.roles, resource Database). Then the privilege scheme, too, is a piece of YAML in Git.

Contents

More