Easily Switch Between Product Types

You can click the drop-down list box to switch between different product types.

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
Situation Awareness
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 Probes

Updated on 2024-12-11 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. A pod with containers reporting that they are not ready does not receive traffic through Kubernetes Services.

A readiness probe periodically detects a pod and determines whether the pod is ready based on its response. Similar to Liveness Probes, there are three types of readiness probes.

  • Exec: kubelet executes a command in the target container. If the command succeeds, it returns 0, and kubelet considers the container to be ready.
  • HTTP GET: The probe sends an HTTP GET request to IP:port of the container. If the probe receives a 2xx or 3xx status code, the container is considered to be ready.
  • TCP Socket: The kubelet attempts to establish a TCP connection with the container. If it succeeds, the container is considered ready.

How Readiness Probes Work

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

Figure 1 How readiness probes work

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, a non-zero 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:alpine
        name: container-0
        resources:
          limits:
            cpu: 100m
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        readinessProbe:      # Readiness probe
          exec:              # Define the ls /ready command.
            command:
            - ls
            - /ready
      imagePullSecrets:
      - name: default-secret

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

# kubectl delete deploy nginx
deployment.apps "nginx" deleted

# kubectl create -f deploy-ready.yaml
deployment.apps/nginx created

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

# kubectl get po
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

Create a Service.

apiVersion: v1
kind: Service
metadata:
  name: nginx        
spec:
  selector:          
    app: nginx
  ports:
  - name: service0
    targetPort: 80   
    port: 8080       
    protocol: TCP    
  type: ClusterIP

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

$ kubectl describe svc nginx
Name:              nginx
......
Endpoints:         
......

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

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

# kubectl get po -o wide
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
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:alpine
        name: container-0
        resources:
          limits:
            cpu: 100m
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        readinessProbe:           # Readiness probe
          httpGet:                # HTTP GET definition
            path: /read
            port: 80
      imagePullSecrets:
      - name: default-secret

TCP Socket

The following example shows how to define a TCP Socket-type probe.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:alpine
        name: container-0
        resources:
          limits:
            cpu: 100m
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        readinessProbe:             # Readiness probe
          tcpSocket:                # TCP socket definition
            port: 80
      imagePullSecrets:
      - name: default-secret

Advanced Settings of a Readiness Probe

Similar to a liveness probe, a 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 is the detailed configuration of the readiness probe.

  • 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, it is considered as a failure.
  • period=10s indicates that the probe is performed every 10s.
  • #success=1 indicates that the probe is considered successful as long as the probe succeeds once.
  • #failure=3 indicates that the probe is considered failed if it fails for three consecutive times.

These are the default configurations when the probe is created. You can customize them as follows:

        readinessProbe:      # Readiness probe
          exec:              # Define the ls /readiness/ready command.
            command:
            - ls
            - /readiness/ready
          initialDelaySeconds: 10    # Readiness probes are initiated 10s after a container starts.
          timeoutSeconds: 2          # The container must respond within 2s. Otherwise, it is considered failed.
          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 container 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