Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

Kubernetes "Readiness probe failed": why a running pod stays 0/1 Ready

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

A pod that shows Readiness probe failed: HTTP probe failed with statuscode: 503 in its events is running, but the kubelet has marked its container not ready. Kubernetes then stops sending traffic to it from the Services that match it. A failed readiness probe does not restart the container. Work out why the check fails (the port, the path, the timeout, the start delay or a dependency the check tests), then change the probe or the application, not the pod.

What the symptom means

The Liveness, Readiness, and Startup Probes page says that for a failed readiness probe "the kubelet marks the container as not ready, and the Pod stops receiving traffic from matching Services". The EndpointSlices page's Conditions section ties the endpoint to the pod: the serving condition "maps to the Pod's Ready condition", and ready is "essentially a shortcut for checking" serving and not terminating. Our reading of those words is that the pod's endpoint stays in the slice and shows ready: false; the page does not say that the endpoint is removed. By contrast, a failed liveness or startup probe makes the kubelet kill the container; a readiness failure does neither, so the restart count stays still.

The kubelet source at tag v1.37.3 records a failed probe as a Warning event with the reason Unhealthy and the message Readiness probe failed: followed by the probe's output. For an HTTP probe, a status code from 200 up to, but not including, 400 is success, as the probes page says; anything else gives HTTP probe failed with statuscode: <code>. If the request itself fails, for example the connection is refused or times out, the message carries the HTTP client's own error text. A TCP probe fails when the socket cannot be established.

Defaults matter. The probes page gives periodSeconds 10, timeoutSeconds 1, failureThreshold 3 and successThreshold 1. The kubelet sends an HTTP probe to the pod's IP address, unless the host field overrides it. For readiness probes specifically, "the result is considered Failure before the initial delay", so a slow-starting application is not ready for a while by design.

The two probe types are independent. The page says "The readiness and liveness probes do not depend on each other to succeed". To wait before a readiness check, use initialDelaySeconds or a startup probe, which holds back liveness and readiness probes until it succeeds.

Likely causes

Cause What you see How to confirm
The application is still starting Events only in the first minutes; the pod then becomes Ready Events stop; the application log shows it finishing start-up
The probe targets the wrong port, scheme or path, or (our reading) the application listens only on 127.0.0.1 A connection error, or a 404 or other status code, on every attempt The readinessProbe in the pod spec differs from what the application serves; our test: a request to the pod IP fails while one to 127.0.0.1 works
The readiness handler returns an error status on purpose, for example 503 while a back-end is unavailable HTTP probe failed with statuscode: 503 The application log shows the failing dependency
The answer takes longer than timeoutSeconds (1 second by default) An HTTP client timeout in the event message A request from inside the container takes longer than the configured timeout

Prove the cause before changing anything

These steps only read. Replace the names with your own.

  1. Find the pod and its READY column:
kubectl get pods -n shop
  1. Read its events. The Debug Pods page gives this as the first step:
kubectl describe pod api-5c8d7f9b6-m4k2z -n shop

Look for Unhealthy and the text after Readiness probe failed:. A status code means the application answered. A connection error or timeout means it did not answer in time.

  1. Read the probe's settings from the pod spec:
kubectl get pod api-5c8d7f9b6-m4k2z -n shop -o yaml

Note path, port, scheme, initialDelaySeconds, periodSeconds, timeoutSeconds and failureThreshold.

  1. Confirm the Service sees the pod as not ready. Find the pod's endpoint in the slices and read its conditions:
kubectl get endpointslices -l kubernetes.io/service-name=api -n shop -o yaml

A bad result is ready: false (and serving: false) on the pod's endpoint, which matches the page's words that serving maps to the pod's Ready condition. A good result is ready: true. The page adds that ready is also always true for a Service with spec.publishNotReadyAddresses set to true, so on such a Service read serving instead.

  1. Read the application's own log:
kubectl logs api-5c8d7f9b6-m4k2z -n shop
  1. Our own advice, if the image carries wget: request the path both ways from inside the container, with the pod's IP address from kubectl get pod -o wide:
kubectl exec api-5c8d7f9b6-m4k2z -n shop -- wget -qO- http://127.0.0.1:8080/ready
kubectl exec api-5c8d7f9b6-m4k2z -n shop -- wget -qO- http://192.0.2.17:8080/ready

Our reading: an answer on 127.0.0.1 and none on the pod's IP address means the application listens on loopback only. The probes page says only that the kubelet requests the pod's IP address.

Fix

Most fixes belong to the application or its dependency. Our advice: an application that listens on loopback only needs a listen address on the pod's IP address, a setting in the application's own configuration outside Kubernetes. A handler that returns 503 because a back-end is down needs that back-end restored by its owner. Before any such edit, the owner saves the application's configuration, and restoring that saved copy backs the change out. A readiness probe that reports a failed dependency is working as designed, and loosening it only sends traffic to a pod that cannot answer.

Probe settings are the part Kubernetes owns. The probe fields cover a slow start (a startup probe or initialDelaySeconds), a slow answer (timeoutSeconds) and a wrong port or path. The probes pages show these fields, for example with these values:

startupProbe:
  httpGet:
    path: /ready
    port: 8080
  failureThreshold: 30
  periodSeconds: 10
readinessProbe:
  httpGet:
    path: /ready
    port: 8080
  periodSeconds: 5
  timeoutSeconds: 3
  failureThreshold: 3

With the startup probe, the application has 30 × 10 = 300 seconds to start, the page's own arithmetic, and the readiness probe does not run until it succeeds.

First save the current state:

kubectl get deployment api -n shop -o yaml > api-deployment-before.yaml
kubectl rollout history deployment/api -n shop

Note the newest revision number in the history output (called N below). The saved file may hold literal values, so keep it private.

Disruptive step: the next command edits the pod template of the Deployment api, so the Deployment replaces its running pods with new ones that use the changed probe.

Open the Deployment in the default editor and change the readinessProbe or add the startupProbe:

kubectl edit deployment/api -n shop
kubectl rollout status deployment/api -n shop

To back out: return to the revision noted before the edit (replace N with that number), wait for it, and compare the result with the saved file. Fields such as resourceVersion and generation will differ.

kubectl rollout undo deployment/api -n shop --to-revision=N
kubectl rollout status deployment/api -n shop
kubectl get deployment api -n shop -o yaml

Example (illustrative): the Deployment api in namespace shop has a readiness probe on /ready, port 8080, with no timeoutSeconds, so the default of 1 second applies. Under load the handler takes about 2.4 seconds. The pod api-5c8d7f9b6-m4k2z on k8s-node1 shows 0/1, kubectl describe pod lists Unhealthy events whose message ends with a client timeout error, and the pod's endpoint in the EndpointSlice shows ready: false. A request from inside the container takes 2.4 seconds, which is more than 1 second and less than 3. The engineer saves the Deployment, sets timeoutSeconds: 3, and the rollout brings up pods that stay Ready. The slow handler is reported to the developers, because 2.4 seconds is a symptom.

Confirm the fix

  1. kubectl get pods -n shop shows the new pods at 1/1.
  2. kubectl get endpointslices -l kubernetes.io/service-name=api -n shop -o yaml shows ready: true on the endpoints of the new pods (always true on a Service with publishNotReadyAddresses set, where serving is the one to read).
  3. kubectl describe pod shows no new Unhealthy events after the change. Allow for the probe period: a pod is marked not ready after failureThreshold failures in a row, nominally 3 × 10 = 30 seconds with the defaults. The probes page says that while a container is not Ready, the readiness probe may run at times other than the configured period.
  4. kubectl rollout status deployment/api -n shop reports that the rollout is complete.

What to watch afterwards

Risks and limits

  • These commands have not been run or lab-tested.
  • The exact words of a connection error or timeout come from the HTTP client and the operating system, not from Kubernetes's documentation, so they may differ by version or operating system.
  • The event text was read from the kubelet source at tag v1.37.3. Other releases may word it differently, and the probes page shows no version range for the defaults.
  • Raising timeoutSeconds or adding a delay can hide a real slowdown. The step above changes how long Kubernetes waits, not how long the application takes.

Sources