Scrivio Interview library
DebuggingIntermediate6 min read · updated 13 November 2026

After sidecar injection was enabled for a namespace, some Spring Boot pods crash at startup with connection refused when fetching configuration, and Kubernetes Jobs in the namespace never complete because their pods keep running after the work is done.

Explain both problems and how to fix them.

Both problems come from container ordering. At startup, the pod's outbound traffic is already redirected to the sidecar, but the application container started before the proxy was ready, so its first call to the config server was refused; we fix it with Istio's holdApplicationUntilProxyStarts or Kubernetes native sidecars, plus retries in the app. Jobs never finish because the sidecar keeps running after the main container exits; native sidecars are stopped automatically when the main containers end, and older setups must tell the proxy to quit.

Why this question is asked

Turning on sidecar injection looks like a configuration change, but it adds a second container to every pod, and Kubernetes originally had no idea that one container was a helper for the other. Interviewers ask this debugging question because both symptoms, crashes at startup and Jobs that never complete, are classic results of that, and the fixes show whether we understand how pods start and stop. In this answer, we will recap how a sidecar intercepts traffic, explain the startup race, fix it in two ways, explain why Jobs hang and how native sidecars solve it, and look at the matching problems at shutdown.

1A Quick Recap: How the Sidecar Takes Over Traffic

When Istio injects a sidecar, it adds an Envoy container to the pod and sets up traffic redirection, either with an init container called istio-init or with the Istio CNI plugin. Either way, by the time the application container starts, iptables rules in the pod's network namespace send every outbound TCP connection to Envoy's local port. The rules are in place immediately, but Envoy itself needs a moment: it must start, connect to istiod, and receive its listeners, routes, endpoints and certificates. Until then, there is nothing ready to accept the redirected connections.

2Problem 1: Why the Pods Crash at Startup

A Spring Boot service that uses Spring Cloud Config, with spring.config.import=configserver:..., fetches its configuration from the config server very early, before most beans are created. In a regular pod, Kubernetes starts the containers in the order they are listed but does not wait for one to be ready before starting the next. So the JVM starts, Spring reaches the config import within a second or two, and opens a connection to the config server. That connection is redirected to Envoy, which is not ready yet, and the result is connection refused. If the config import is not optional, startup fails, the container exits, and Kubernetes restarts it. Some pods succeed because their sidecar happened to win the race, which is why only some pods crash.

Step throughThe startup race
KubeletApp containerEnvoy sidecarConfig server
start app container
start sidecar (no waiting in between)
GET config, redirected by iptables
connection refused: not listening yet
startup fails, container exits
config from istiod arrives, now ready

6 messages in order. Play them, or step through them one at a time.

The redirect is in place before the proxy can serve it.

3Fix: Make the Application Wait for the Proxy

Istio has an option for exactly this race: holdApplicationUntilProxyStarts. When it is on, the injector places the proxy container first and adds a postStart hook that blocks until Envoy is ready. Kubernetes runs postStart before starting the next container, so the application starts only after the proxy can serve traffic. It can be set mesh-wide in meshConfig.defaultConfig or per pod with an annotation.

YAML
# per pod or per deployment template
metadata:
annotations:
proxy.istio.io/config: |
holdApplicationUntilProxyStarts: true

The cleaner, newer fix is Kubernetes native sidecars. A native sidecar is declared as an init container with restartPolicy: Always. Kubernetes starts init containers in order, and for a native sidecar it waits until the container has started (and passed its startup probe, if one is defined) before moving on, but unlike a normal init container it keeps running alongside the app. The feature has been enabled by default since Kubernetes 1.29 and reached general availability in 1.33. Istio can inject its proxy as a native sidecar; whether it does so by default depends on your Istio version, so check that and the ENABLE_NATIVE_SIDECARS setting.

4Making Startup Tolerant Anyway

Ordering fixes the common case, but the network can still be briefly unavailable: istiod may be slow, the config server may be restarting, or DNS may lag. A service that crashes on the first refused connection turns every small delay into a restart loop. Spring Cloud Config can retry the import with backoff when spring-retry is on the classpath and spring.cloud.config.fail-fast is true.

Properties
spring.config.import=configserver:http://config:8888
spring.cloud.config.fail-fast=true
spring.cloud.config.retry.initial-interval=1000 # 1 s
spring.cloud.config.retry.multiplier=1.5
spring.cloud.config.retry.max-attempts=8 # about 30 s in total before failing

With retries, a delay of a few seconds becomes a slower start instead of a crash. Notice that fail-fast is still true: if the config server is really gone, we want the pod to fail clearly rather than start with missing configuration.

5Problem 2: Why Jobs Never Complete

A Kubernetes Job is complete when its pod succeeds, which means all of the pod's containers have terminated successfully. The batch container finishes its work and exits with code 0, but the Envoy sidecar is a server: it has no reason to exit. So the pod stays Running forever, the Job never completes, and with CronJobs the pods pile up.

Native sidecars fix this directly. Kubernetes knows that a sidecar init container is a helper, so when all regular containers of the pod have finished, it sends the sidecars a termination signal, and the pod completes with the status of the main containers. On older clusters or older Istio versions, the job itself must tell the proxy to exit when it is done, by calling the pilot agent's quit endpoint on localhost.

YAML
# older setups: the job's command ends by stopping the proxy
run-batch-import && curl -fsS -X POST http://localhost:15020/quitquitquit
# with native sidecars: nothing needed, the sidecar is stopped after the main container

The quit call works but is fragile: if the job crashes before reaching it, the pod still hangs. That is why native sidecars are the better long-term fix, and why some teams simply exclude short batch jobs from the mesh if they do not need its features.

6Follow-up questions

What ordering problems can appear at shutdown?

When a pod is deleted, Kubernetes signals all containers at once. If the sidecar exits first, the application loses its network while it is still finishing in-flight requests or flushing messages, and those calls fail. Istio delays proxy shutdown with a drain duration and can wait for active connections to end, and native sidecars are stopped only after the main containers have exited, which gives the right order. The application should also use Spring Boot's graceful shutdown (server.shutdown=graceful) so it finishes requests before exiting.

How would you confirm the startup race rather than a broken config server?

Look at the timing in the logs: the app's connection refused appears within a second or two of the container start, while the sidecar logs show it became ready slightly later. The same request succeeds after a restart, and kubectl describe pod shows restarts only on the application container. A broken config server would fail consistently and from all pods.

Can the application just wait for a fixed time at startup?

A sleep hides the problem and slows every start, and it is never the right length. Waiting for proxy readiness, through the Istio option or native sidecars, plus retry with backoff in the app, handles both fast and slow cases.

7Conclusion

In this answer, we saw that both failures come from container ordering in a pod with a sidecar. At startup, traffic is redirected to Envoy before Envoy is ready, so early calls such as the Spring Cloud Config import are refused; holdApplicationUntilProxyStarts or Kubernetes native sidecars (init containers with restartPolicy: Always, on by default since 1.29) make the app wait, and retries with backoff make startup tolerant. Jobs hang because the sidecar never exits; native sidecars are stopped automatically when the main container finishes, and older setups call the proxy's quit endpoint.

What to say in the interviewAbout 80 seconds aloud

Open with

Both problems are about container ordering. With injection, iptables redirects all of the pod's outbound traffic to Envoy right away, but Kubernetes starts the app container without waiting for the proxy to be ready.

Then, if they want more

Spring Cloud Config fetches configuration very early, so that call hits a proxy that is not listening yet, gets connection refused, and the pod crashes; it only happens on some pods because it is a race.

I would fix it by making the app wait for the proxy, either Istio's holdApplicationUntilProxyStarts, which puts the proxy first with a postStart hook that blocks until it is ready, or Kubernetes native sidecars, which are init containers with restartPolicy Always, on by default since 1.29, that start before the app containers.

I would also enable config retries with backoff so a short network delay is a slow start, not a crash. The Jobs never complete because a Job needs all containers in the pod to exit, and the sidecar is a server that never exits. Native sidecars fix that too, since Kubernetes stops them when the main containers finish.

On older setups, the job has to call the proxy's quitquitquit endpoint on localhost at the end, which is fragile if the job crashes first.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain both problems and how to fix them.": https://scrivio-interview-library.netlify.app/architecture/load-balancing-networking/614bc35e1a/