Interview Prep/Real-World Interview/Write-a-Kubernetes-manifest tasks

Write an init container that waits for the database before the app starts.

BeginnerHands-onWrite-a-Kubernetes-manifest tasks
Answer
spec:
  initContainers:
    - name: wait-for-db
      image: busybox:1.36
      command: ["sh", "-c", "until nc -z postgres 5432; do echo waiting for db; sleep 2; done"]
  containers:
    - name: app
      image: myapp:1.0

Key trick → Init containers run to completion, one at a time, before app containers start. Still make the app retry its connections, because the database can disappear later too.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Kubernetes-manifest tasks