0
0
Kubernetesdevops~5 mins

Readiness probe concept in Kubernetes - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes an application inside a container takes time to start and be ready to serve traffic. A readiness probe helps Kubernetes know when the app is ready so it only sends user requests to containers that can handle them.
When your app needs to load data or initialize before it can accept requests
When you want to avoid sending traffic to a container that is still starting up
When you want Kubernetes to automatically stop sending traffic if your app becomes unhealthy
When you want to improve user experience by only routing to ready containers
When you want to manage rolling updates smoothly by checking readiness before switching traffic
Config File - readiness-pod.yaml
readiness-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: example-readiness-pod
spec:
  containers:
  - name: example-app
    image: nginx:1.23
    readinessProbe:
      httpGet:
        path: /index.html
        port: 80
      initialDelaySeconds: 5
      periodSeconds: 5

This YAML file defines a Pod with one container running nginx.

The readinessProbe uses an HTTP GET request to check if the /index.html page is available on port 80.

initialDelaySeconds waits 5 seconds before the first check to give the app time to start.

periodSeconds sets the probe to run every 5 seconds.

Commands
This command creates the Pod with the readiness probe configured. Kubernetes will start the container and begin checking readiness after the initial delay.
Terminal
kubectl apply -f readiness-pod.yaml
Expected OutputExpected
pod/example-readiness-pod created
This command shows the status of the Pod including if it is ready to receive traffic.
Terminal
kubectl get pods example-readiness-pod
Expected OutputExpected
NAME READY STATUS RESTARTS AGE example-readiness-pod 1/1 Running 0 10s
This command gives detailed information about the Pod, including readiness probe results and events.
Terminal
kubectl describe pod example-readiness-pod
Expected OutputExpected
Name: example-readiness-pod Namespace: default Status: Running Containers: example-app: Container ID: docker://abcdef123456 Image: nginx:1.23 Ready: True Restart Count: 0 Readiness: http-get http://:80/index.html delay=5s timeout=1s period=5s #success=1 #failure=3 Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 1m default-scheduler Successfully assigned default/example-readiness-pod to node-1 Normal Pulled 1m kubelet Container image "nginx:1.23" already present on machine Normal Created 1m kubelet Created container example-app Normal Started 1m kubelet Started container example-app
Key Concept

If you remember nothing else from this pattern, remember: readiness probes tell Kubernetes when your app is ready to receive traffic, preventing requests from going to containers that are not yet ready.

Common Mistakes
Not setting initialDelaySeconds causing the probe to fail before the app starts
The probe runs too early and marks the container as not ready even though it is just starting up.
Set initialDelaySeconds to a value that gives your app enough time to start before the first probe.
Using a wrong path or port in the readiness probe
The probe will always fail because it cannot reach the correct endpoint, so Kubernetes never marks the container ready.
Verify the path and port in the readiness probe match what your app actually serves.
Confusing readiness probe with liveness probe
Readiness controls traffic routing, liveness controls container restarts; mixing them can cause unexpected restarts or traffic issues.
Use readiness probes to control traffic and liveness probes to check if the container should be restarted.
Summary
Create a Pod with a readiness probe that checks an HTTP endpoint to confirm the app is ready.
Use kubectl apply to create the Pod and kubectl get pods to check if it is ready.
Use kubectl describe pod to see detailed readiness probe results and events.