Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Readiness Probe

Updated on 2024-11-01 GMT+08:00

After a pod is created, the Service can immediately select it and forward requests to it. However, it takes time to start a pod. If the pod is not ready (it takes time to load the configuration or data, or a preheating program may need to be executed), the pod cannot process requests, and the requests will fail.

Kubernetes solves this problem by adding a readiness probe to pods. The Service can forward requests to a pod only after the probe detects that the pod is ready.

The readiness probe periodically detects a pod and determines whether the pod is ready based on the response. Similar to Liveness Probe, CCI also supports two types of readiness probes.

  • HTTP GET: The probe sends an HTTP GET request to the container by using IP:port. If the probe receives a 2xx or 3xx status code, the container is ready.
    NOTE:

    You need to configure the following annotation for the pod to make timeoutSeconds take effect:

    cci.io/httpget-probe-timeout-enable:"true"

    For details, see the example in Advanced Configuration of Liveness Probe.

  • Exec: The probe runs a command in the container and checks the exit status code. If the exit status code is 0, the container is ready.

Working Principles of the Readiness Probe

If you run the kubectl describe command to query the Service, information similar to the following is displayed:

$ kubectl describe svc nginx -n $namespace_name
Name:              nginx
......
Endpoints:         192.168.113.81:80,192.168.165.64:80,192.168.198.10:80
......

Endpoints is displayed, which is also a resource object in Kubernetes.

$ kubectl get endpoints -n $namespace_name
NAME         ENDPOINTS                                               AGE
nginx        192.168.113.81:80,192.168.165.64:80,192.168.198.10:80   14m

192.168.113.81:80 is the IP:port of the pod. You can run the following command to view the IP address of the pod, which is the same as the preceding IP address.

# kubectl get pods -o wide -n $namespace_name
NAME                     READY     STATUS    RESTARTS   AGE       IP                                                                             
nginx-55c54cc5c7-49chn   1/1       Running   0          1m        192.168.198.10
nginx-55c54cc5c7-x87lb   1/1       Running   0          1m        192.168.165.64
nginx-55c54cc5c7-xp4c5   1/1       Running   0          1m        192.168.113.81

Endpoints can be used as a readiness probe. When the pod is not ready, IP:port is deleted from the Endpoints and is added to the Endpoints after the pod is ready, as shown in the following figure.

Figure 1 Working principles of the readiness probe

Exec

The Exec mode is the same as the HTTP GET mode. As shown below, the probe runs the ls /ready command. If the file exists, 0 is returned, indicating that the pod is ready. Otherwise, another status code is returned.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:latest
        name: container-0
        resources:
          limits:
            cpu: 500m
            memory: 1024Mi
          requests:
            cpu: 500m
            memory: 1024Mi
        readinessProbe:      # Readiness Probe
          exec:              # Define the ls /ready command.
            command:
            - ls
            - /ready
      imagePullSecrets:
      - name: imagepull-secret

Save the definition of the Deployment to deploy-read.yaml, delete the previously created Deployment, and use deploy-read.yaml to recreate the Deployment.

# kubectl delete deploy nginx -n $namespace_name
deployment.apps "nginx" deleted

# kubectl create -f deploy-read.yaml -n $namespace_name
deployment.apps/nginx created

The nginx image does not contain the /ready file. Therefore, the container is not in Ready state after the creation, as shown below. Note that the value in the READY column is 0/1, indicating that the container is not ready.

# kubectl get po -n $namespace_name
NAME                     READY     STATUS    RESTARTS   AGE
nginx-7955fd7786-686hp   0/1       Running   0          7s
nginx-7955fd7786-9tgwq   0/1       Running   0          7s
nginx-7955fd7786-bqsbj   0/1       Running   0          7s

Check the Service again. If there are no values in the Endpoints line, no Endpoints are found.

$ kubectl describe svc nginx -n $namespace_name
Name:              nginx
......
Endpoints:         
......

If a /ready file is created in the container to make the readiness probe succeed, the container is in the Ready state. Check the pod and Endpoints. It is found that the container for which the /ready file is created is ready and an Endpoints record is added.

# kubectl exec -n $namespace_name nginx-7955fd7786-686hp -- touch /ready 

# kubectl get po -o wide -n $namespace_name
NAME                     READY     STATUS    RESTARTS   AGE       IP
nginx-7955fd7786-686hp   1/1       Running   0          10m       192.168.93.169 
nginx-7955fd7786-9tgwq   0/1       Running   0          10m       192.168.166.130
nginx-7955fd7786-bqsbj   0/1       Running   0          10m       192.168.252.160

# kubectl get endpoints -n $namespace_name
NAME       ENDPOINTS           AGE
nginx      192.168.93.169:80   14d

HTTP GET

The configuration of a readiness probe is the same as that of a liveness probe, which is also in the containers field of the pod description template. As shown below, the readiness probe sends an HTTP request to the pod. If the probe receives 2xx or 3xx, the pod is ready.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:latest
        name: container-0
        resources:
          limits:
            cpu: 500m
            memory: 1024Mi
          requests:
            cpu: 500m
            memory: 1024Mi
        readinessProbe:           # readinessProbe
          httpGet:                # HTTP GET definition
            path: /read
            port: 80
      imagePullSecrets:
      - name: imagepull-secret

Advanced Configuration of Readiness Probe

Similar to the liveness probe, the readiness probe also has the same advanced configuration items. The output of the describe command of the nginx pod is as follows:

Readiness: exec [ls /var/ready] delay=0s timeout=1s period=10s #success=1 #failure=3

This line indicates the parameter configuration of the readiness probe. The meanings of the parameters are as follows:

  • delay=0s indicates that the probe starts immediately after the container is started.
  • timeout=1s indicates that the container must respond to the probe within 1s. Otherwise, the detection fails.
  • period=10s indicates that the detection is performed every 10s.
  • #success=1 indicates that the detection is successful after succeeding once.
  • #failure=3 indicates that the container will be restarted after three consecutive detection failures.

These are set by default when the probe is created. You can also manually configure the parameters as follows:

        readinessProbe:      # Readiness Probe
          exec:              # Define the ls /readiness/ready command.
            command:
            - ls
            - /readiness/ready
          initialDelaySeconds: 10    # Readiness probes are initiated after the container has started for 10s.
          timeoutSeconds: 2          # The container must respond to the probe within 2s, or the detection fails.
          periodSeconds: 30          # The probe is performed every 30s.
          successThreshold: 1        # The container is considered ready as long as the probe succeeds once.
          failureThreshold: 3        # The probe is considered to be failed after three consecutive failures.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback