During a rolling update, you need to ensure that the updated pods are ready before they are launched to receive traffic. You can configure readiness gates to ensure the readiness of pods before they are launched. The Application Load Balancer (ALB) Ingress controller allows you to enable readiness gates to continuously monitor the status of pods in a Container Service for Kubernetes (ACK) cluster. After the status of the pods changes to Ready, the pods are launched and added to a backend server group. Then, traffic is forwarded to the pods.
Prerequisites
An ACK managed cluster or ACK Serverless cluster is created. For more information, see Create an ACK Serverless cluster or Create an ACK managed cluster.
The ALB Ingress controller is installed in the cluster. For more information, see Manage the ALB Ingress controller.
NoteTo use an ALB Ingress to access Services deployed in an ACK dedicated cluster, you need to first authorize the cluster to access the ALB Ingress controller. For more information, see Authorize an ACK dedicated cluster to access the ALB Ingress controller.
A kubectl client is connected to the cluster. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
How it works
ACK uses liveness probes, readiness probes, and startup probes to check the health status, readiness, and startup conditions of pods in order to improve the availability of applications. When you configure liveness probes, readiness probes, and startup probes, you can specify the probing interval, timeout period, healthy threshold, and unhealthy threshold. You can define these probes with commands, TCP sockets, or HTTP requests to verify the health of containers. For more information, see Configure Liveness, Readiness and Startup Probes.
Probe type | Description |
Liveness probe | The kubelet uses liveness probes to check whether containers are alive, kills unhealthy containers, and then restarts the containers based on the restart policy. If a container is not probed by liveness probes, the kubelet considers that the container returns Success for liveness probes and therefore the container is alive. |
Readiness probe | Readiness probes are used to check whether a container is ready to receive requests. Only pods that are in the Ready state can receive requests. The relationship between Services and endpoints depends on the Ready state of the pod:
|
Startup probe | The kubelet uses startup probes to learn when a container has launched. You can use startup probes to ensure that liveness probes and readiness probes are sent to a container only after the container has launched. Startup probes can be used to perform liveness checks on slow starting containers so that the containers are not killed by the kubelet before they are started. |
If readiness probes are used, the value of the Ready field of a pod is determined by the kubelet based on the status of the containers in the pod. However, for complex applications, you may need to control the readiness Services in containers in a fine-grained manner. To do this, you need to control the value of the Ready field of pods.
Readiness gates allow you to set one or more custom readiness conditions to check whether a pod is ready. These custom conditions are set on an external controller. Kubernetes considers that a pod is ready only when all conditions specified in readiness gates are True.
You can configure readiness gates on the ALB Ingress controller to allow an ACK cluster to continuously monitor the status of pods. A pod is not considered started until it enters the Ready state. The started pod will be added to a backend server group, and traffic will be forwarded to the pod.
You can configure the custom condition target-health.alb.k8s.alibabacloud
for readiness gates in the Deployment. This allows the ACK cluster to continuously monitor the status of pods. The ACK cluster considers a pod is ready and starts to forward traffic to the pod only after the ALB Ingress controller adds the pod to a backend server group.
Procedure
Create a file named tea-service.yaml and configure custom conditions for readiness gates.
Create a file named tea-service.yaml and add the following content to the file to deploy a Deployment named
tea
and a Service namedtea-svc
. Configure custom conditions for readiness gates in the Deployment:target-health.alb. Kubernetes. alibabacloud
. This allows the ACK cluster to continuously monitor the status of pods. A pod is not considered started until it enters the Ready state. The started pods are added to a backend server group.apiVersion: apps/v1 kind: Deployment metadata: name: tea spec: replicas: 3 selector: matchLabels: app: tea template: metadata: labels: app: tea spec: containers: - name: tea image: registry.cn-hangzhou.aliyuncs.com/acs-sample/nginxdemos:latest ports: - containerPort: 80 # Configure readiness gates readinessGates: - conditionType: target-health.alb.k8s.alibabacloud --- apiVersion: v1 kind: Service metadata: name: tea-svc spec: ports: - port: 80 targetPort: 80 protocol: TCP selector: app: tea type: NodePort
Run the following command to deploy the Deployment andService:
kubectl apply -f tea-service.yaml
Run the following command to check whether the configuration of readiness gates takes effect:
kubectl get pods -o yaml |grep 'target-health'
Expected output:
-conditionType:target-health.alb.k8s.alibabacloud message:correspondingconditionofpodreadinessgate"target-health.alb.k8s.alibabacLoud"
References
For more information about how to access Services in ACK clusters by using ALB Ingresses, see Get started with ALB Ingresses.
ALB Ingresses are API objects used to manage external user access to Services deployed in ACK clusters and provide Layer 7 load balancing capabilities. For more information, see Advanced ALB Ingress configurations.
For more information about how to troubleshoot issues related to ALB Ingresses, see ALB Ingress controller troubleshooting and ALB Ingress FAQ.