Search code examples
kubernetesgoogle-cloud-platformgoogle-kubernetes-engine

How to set up Kubenetes not mark the pod as running while not all containers ready


This is probably a basic question: when I use kubectl rollout start deployment ... to roll start my pods, I find the POD is marked as Running state while there are still more containers not up yet.

If I understand correctly, once a POD is marked Running, it will start serving the traffic, right? In fact, the POD is not ready since waiting for more containers to be up.

How do I prevent Kube from marking it as Running until all containers are running?

Thanks!

one example


Solution

  • Kubernetes pods will not receive traffic until all of their containers are ready. You can configure a probe to check whether each container is ready via container readiness probes.

    If no readiness probe is configured for a container, it will be marked as ready to receive traffic once it has started running. This is not ideal for most servers or databases.

    Below is a sample readiness probe that queries port 80 through HTTP. More info in the documentation.

    readinessProbe:
      httpGet:
        port: 80
        path: /
      initialDelaySeconds: 5
      periodSeconds: 5
      failureThreshold: 5
    
    • initialDelaySeconds indicates a delay after which the probe will start to run.
    • periodSeconds sets the period to wait between each readiness check
    • failureThreshold the number of probe failures that can be tolerated. After failureThreshold failures, the container will be marked as not ready. Initially, the container will be marked as not ready as well.

    Note: Readiness and liveness probes run consistently for the whole lifespan of a container. They are meant to be lightweight, meaning that they won't take up considerable resources.