Search code examples
kubernetescontainerskubernetes-podkubernetes-service

Kubernetes: Service routing to pods with multiple containers


I am currently facing an issue in my Kubernetes cluster. While debugging that I had a question in mind which I didn't know the answer to.

I am using AWS EKS, version 1.15 but I don't think my question is related to any specific cloud or kubernetes version

I have a deployment. It has multiple containers. There is a service that exposes this deployment.

Suppose the deployment has 2 containers, C1 and C2. C1 takes 1 second to start but C2 takes 30 seconds to start(crazy!). So, when I start the pod at time t1, what happens is that once C1 starts immediately and the pod goes into running status but only 1/2 containers are ready. The pod C2 finally starts at time t2(t1+30seconds). At time t2, 2/2 containers are ready.

Also assume that C1 takes the incoming request from the service, it does something and then forwards request to C2, C2 does something and then returns it to C1. C1 finally returns to service and the response is served to client.

So, my question is, during the time between t2 and t1, when pod is in running state but only 1/2 container is ready, would the service forward requests to the pods?

Put another way, when does the service forward request to pods? If they are in running state and not matter how many containers are ready? OR if they are in running state and all containers are ready?

My thinking is that service won't forward as it won't make any sense if all the pods are not ready but I don't have any proof/document to justify it.


Solution

  • ...when pod is in running state but only 1/2 container is ready, would the service forward requests to the pods?

    No.

    when does the service forward request to pods? If they are in running state and not matter how many containers are ready? OR if they are in running state and all containers are ready?

    My thinking is that service won't forward as it won't make any sense if all the pods are not ready but I don't have any proof/document to justify it.

    Here it is :)

    Official documentation says that "...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. One use of this signal is to control which Pods are used as backends for Services. When a Pod is not ready, it is removed from Service load balancers..."

    Additionally it says:

    "...applications are temporarily unable to serve traffic... an application might depend on external services ... In such cases, you don't want to kill the application, but you don’t want to send it requests either. Kubernetes provides readiness probes to detect and mitigate these situations. A pod with containers reporting that they are not ready does not receive traffic through Kubernetes Services..."

    Readiness probe is used to detect the situation when traffic shall not be sent to App.

    My thinking is that service won't forward as it won't make any sense if all the pods are not ready

    You are absolutely right here.

    I hope that helps.