I have two applications - app1 and app2, where app1 is a config server
that holds configs for app2. I have defined /readiness
endpoint in app1 and need to wait till it returns OK
status to start up pods of app2.
It's crucial that deployment of app2 wait till kubernetes
receives Http Status OK
from /readiness endpoint in app1 as it's a configuration server and holds crucial configs for app2.
Is it possible to do this kind of deployment dependency?
If the output from a specific pod is desired, run the command kubectl describe pod pod_name --namespace kube-system . The Status field should be "Running" - any other status will indicate issues with the environment. In the Conditions section, the Ready field should indicate "True".
Use Wait command We utilize the 'wait' command to recess until the pods meet the requirements. Use kubectl apply to relate the variations to the cluster and wait a randomly set amount of time (60 seconds) to check the status of the pod. At this point, we expect the fresh deployment to be active and the old one removed.
The restartPolicy applies to all containers in the Pod. restartPolicy only refers to restarts of the containers by the kubelet on the same node. After containers in a Pod exit, the kubelet restarts them with an exponential back-off delay (10s, 20s, 40s, …), that is capped at five minutes.
This page provides an overview of init containers: specialized containers that run before app containers in a Pod. Init containers can contain utilities or setup scripts not present in an app image. You can specify init containers in the Pod specification alongside the containers array (which describes app containers).
You need to use initContainers
. Following is an example of how you can do in your YAML
file
initContainers: - name: wait-for-other-pod image: docker.some.image args: - /bin/sh - -c - > set -x; while [ $(curl -sw '%{http_code}' "http://www.<your_pod_health_check_end_point>.com" -o /dev/null) -ne 200 ]; do sleep 15; done
I have used curl
to hit the health check endpoint, you can use any other UNIX command to check if the other pod is ready.
Yes, it's possible using Init Containers (also, see this blog post for some background re timing) but a better, more Kubernetes-native pattern is to use retries and timeouts rather than hard-coding dependencies in this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With