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.
More on Write-a-Kubernetes-manifest tasks
Write a Deployment and Service for an Nginx app with 3 replicas, resources and probes.BeginnerAdd an HPA that scales the Deployment between 3 and 15 pods at 70% CPU.BeginnerFix this broken Deployment YAML.BeginnerWrite a ConfigMap and Secret and inject them as environment variables and as a mounted file.IntermediateWrite an Ingress that routes `/api` to the api service and `/` to the web service with TLS.IntermediateWrite a pod spec with a hardened securityContext.Intermediate