A pod has two containers: A and B, A needs to call B so it must wait for B to get ready. Currently, my implementation for this readiness detection is using "Readiness Probe". However, there is a problem. No boolean value like "ready" for the container structure in "k8s.io/api/core/v1.Container". This does not make sense to me, shouldn't there be such a field so that another container can easily detect the status? Or I made a mistake about this "Readiness Probe" in the first place?
I have noticed that if a container's readiness is not ok, then its container is not going to be created. So maybe I can look through the pod and check if B's container is created, this might be the reason why "k8s.io/api/core/v1.Container" doesn't have a boolean field for "Readiness Probe".
My question is: is it ok to use a container's existence as an indicator of "Readiness Probe" ?
CodePudding user response:
No, the fact that a Pod's container exists does not mean that the Container is ready. Think about a Java container that takes 30 seconds to bootstrap. The container will be existing and not ready for the first 30 seconds.
What you need to do is check the Container State in the Pod Status: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-states
More specifically, you need to iterate through the array status.containerStatuses
until you find the name of the container you are interested in, and then check the ready
field.
From the docs (https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#PodStatus):
containerStatuses.ready (boolean): Specifies whether the container has passed its readiness probe.