Kubernetes: Wait until another pod is ready

November 2, 2020

The idea is to wait inside an init-container until the health check is successful. The health check, in this case, is the HTTP response code equal to 200.

  • This init-container will continue after the service returns 200.
  • If the init-container doesn't complete, the container will not be executed.
initContainers:
- name: wait-for-webserver
  image: curlimages/curl:latest
  command: ["/bin/sh","-c"]
  args: ["while [ $(curl -sw '%{http_code}' http://webserver.svc.cluster.local -o /dev/null) -ne 200 ]; do sleep 5; echo 'Waiting for the webserver...'; done"]
Read more