How Readiness probe in k8s works
Deepak Kumar
Propelling AI To Reinvent The Future || Mentor|| Leader || Innovator || Machine learning Specialist || Distributed architecture | IoT | Cloud Computing
Introduction
Laymen explanation
If you have used k8s for your services, you might have thought about controlling incoming traffic. You may want that apps catering service traffic should only accept traffic once it is ready. Otherwise, during initialisation only, app will get traffic. It can be a waste of computation and even result in app crash (practical case where app developer has not handled this unexpected case well). Even initialisation time may increase due to processing of such unwanted traffic. In the other side, caller App will receive failure as recipient App is still not ready.
This document helps in this regard.
Technical explanation
The kubelet uses readiness probes to know when a Container is ready to start accepting traffic. A Pod is considered ready when all of its Containers are ready. With readiness probes, Kubernetes will not send traffic to a pod until the probe is successful.
Kubelet flow
Autoscale and readiness probe
In the auto-scale case, when necessary Cluster is going to add Pods when it sees fit. Once a Pod is added the Cluster needs information from the Pod that the Pod is ready to start having traffic routed to the Pod. Now if your Microservice requires a configuration lookup or some other process to complete prior to being ready then you need to let Kubernetes know when it should start routing requests to the Pod. This is done via readiness probe.