K8s 1.29 StatefulSet ordering - DNS not ready on first pod
We're running K8s 1.29 on a 3-node Hetzner cluster and hit a weird issue with StatefulSet rollouts. When deploying a PostgreSQL 16 StatefulSet, the first pod tries to initialize before the DNS headless service resolves the other pod names.
The init container runs immediately but can't reach postgres-1.postgres.default.svc.cluster.local. We added podManagementPolicy: Parallel but that defeats the purpose.
Anyone else hit this? Should we be using an init container that waits for the service, or is there a proper K8s way to handle this? Looking at examples from the community but most skip this detail.
Edited at 25 Mar 2026, 23:10
The DNS headless service should be ready before pod-0 even starts—that's the whole point of Ordered pod management. Check if your service selector is actually matching the pods. Also, what does your init container logic look like? Sometimes the issue is that you're querying DNS too early in the init phase before kubelet has even registered the pod with the service. Try adding a small sleep before the DNS lookup, or use nslookup with retries instead of a single shot. Pg-specific tip: use pg_basebackup with a retry loop in your init container rather than relying on headless DNS resolution for initial sync—much more robust.
Good point, thanks! Checked the service selector and it's correct. Turns out the DNS was propagating slower than expected in our Hetzner setup. Added a wait-for-dns init container and it's working now. Appreciate the nudge to double-check the service config!