Help Center/ Cloud Container Engine/ Best Practices/ Disaster Recovery/ High-Availability Deployment of Applications in CCE
Updated on 2026-11-16 GMT+08:00

High-Availability Deployment of Applications in CCE

In a cloud-native environment, containerized applications support efficient service delivery through auto scaling and agile iteration. However, there are still uncertainties and risks in the underlying infrastructure, scheduling logic, storage dependencies, and application lifecycle management. These include single-node or AZ failures, inappropriate rolling update policies, pod scheduling conflicts, and mismatch between EVS disks and node AZs, all of which can cause service interruptions or unavailability.

To achieve end-to-end high availability for CCE, you cannot rely solely on multi-replica deployment. Instead, you need to build a protection system that spans the infrastructure layer, application scheduling layer, and stateful storage layer and covers the following six core dimensions:
  • Pod topology distribution: Pod topology spread constraints or anti-affinity policies are used to evenly distribute workloads across AZs and nodes, preventing single points of failure.
  • Pod disruption budget: Voluntary interruptions are controlled to ensure the minimum number of available replicas for services, preventing service unavailability caused by rolling updates or node evictions.
  • Pod health management: Readiness, liveness, and startup probes are configured to automatically detect and rectify exceptions. This ensures that traffic is only forwarded to healthy pods.
  • Graceful lifecycle: preStop hooks and termination grace periods are configured to ensure lossless traffic drain-off.
  • Node HA: Physical machine anti-affinity and multi-AZ node pools are used to isolate underlying hardware faults.
  • Cross-AZ storage adaptation: Delayed storage class binding addresses the limitation of cross-AZ EVS disk attachment, preventing scheduling failures for stateful applications.

This section integrates three practices: application deployment, node pool management, and storage scheduling, to provide a comprehensive solution for end-to-end high availability of CCE workloads.

Application Layer HA

Deploying an Application

Pod Topology Distribution

Consider a cluster with four nodes distributed across three AZs.

  • Solution 1: Using Topology Spread Constraints (Recommended)

    Topology spread constraints (specified via topologySpreadConstraints), provide precise control over how pods are distributed across different topology domains such as AZs and individual nodes. This mechanism allows multiple topology dimensions to be configured simultaneously, ensuring even pod distribution without interference from other workloads in the cluster.

    Configuration example:

    When four replicas are deployed across three AZs, the scheduler attempts to distribute them as evenly as possible, typically resulting in a distribution of two pods in one zone and one pod in each of the remaining two zones. If one AZ has no available nodes due to resource constraints or failure, the scheduler may adjust the distribution to two pods in each of two zones and zero in the third. The scheduler consistently prioritizes even distribution to prevent all pods from being concentrated in a single AZ.

    ...
    spec:
      replicas: 4
      template:
        spec:
          topologySpreadConstraints:
          # Constraint 1: Even distribution across AZs
          - maxSkew: 1                     # The maximum allowed difference in the number of pods between any two AZs cannot exceed one.
            topologyKey: topology.kubernetes.io/zone
            whenUnsatisfiable: DoNotSchedule  # Hard constraint. If the scheduler cannot find a node that satisfies this distribution requirement, the pod remains in a pending state and scheduling is prohibited. Alternatively, ScheduleAnyway can be used.
            labelSelector:
              matchLabels:
                app: nginx-ha
          # Constraint 2: Even distribution across nodes (optional, further distribution across individual nodes)
          - maxSkew: 1
            topologyKey: kubernetes.io/hostname
            whenUnsatisfiable: DoNotSchedule
            labelSelector:
              matchLabels:
                app: nginx-ha
    ...

    Parameters:

    • maxSkew: 1: defines the maximum allowed difference in pod count between any two topology domains, and it is set to 1 to achieve the most even distribution possible.
    • whenUnsatisfiable: DoNotSchedule: The constraint operates as a hard requirement. If the scheduler cannot identify a node that satisfies the distribution conditions, the pod remains in a pending state until suitable resources become available.
    • whenUnsatisfiable: ScheduleAnyway: The constraint operates as a soft preference. The scheduler attempts to distribute pods as evenly as possible across topology domains, but if this even distribution cannot be achieved, the scheduler proceeds with placement rather than leaving the pod pending.
  • Solution 2: Using Pod Anti-affinity

    Pod anti-affinity offers greater flexibility than topology spread constraints and is better suited for complex scheduling logic. The preferredDuringScheduling rule enables soft preferences, allowing the scheduler to preferentially distribute pods across nodes in different AZs. When stricter guarantees are necessary, the requiredDuringScheduling rule can be used to enforce hard constraints that prevent pods from being scheduled to the same topology domain.

    Configuration example:

    ...
    affinity:
      podAntiAffinity:
        preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 80                      # High weight: cross-AZ deployment preferred
          podAffinityTerm:
            labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - nginx-ha
            topologyKey: topology.kubernetes.io/zone
        - weight: 20                      # Low weight: cross-node scheduling within the same AZ
          podAffinityTerm:
            labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - nginx-ha
            topologyKey: kubernetes.io/hostname
    ...

Pod Disruption Budget

A PDB is a Kubernetes resource that limits voluntary disruptions to protected workloads. Voluntary disruptions are pod deletions initiated proactively by the system or an administrator, such as during rolling updates of Deployments or manual pod deletion.

The PDB safeguards service capacity by enforcing either a minAvailable threshold or a maxUnavailable limit.

Configuration example:

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: nginx-ha-pdb
spec:
  minAvailable: 2        # At least two pods must be available.
  selector:
    matchLabels:
      app: nginx-ha
  • minAvailable: the minimum number of pods that must remain available at any given time. This value can be expressed as an absolute number, such as 2, or as a percentage of the total replica count, such as 50%.
  • maxUnavailable: the maximum number of pods that may be simultaneously unavailable, which can also be specified as either an absolute number or a percentage.
  • selector: uses a label selector to match the set of pods to which the PDB applies.

minAvailable and maxUnavailable are mutually exclusive; only one of these two fields may be configured in a single PDB.

Pod Health Management

A probe is a diagnostic check that the kubelet periodically performs against a container. Based on the result, the kubelet determines the health status of the pod and takes appropriate actions. Kubernetes provides three types of probes:

  • readinessProbe: determines whether a pod is ready to receive traffic. If this probe fails, the pod is removed from the endpoints of its associated Service, but the container itself is not restarted. This mechanism is commonly used to control the pace of rolling updates.
  • livenessProbe: determines whether a pod is healthy and functioning correctly. If this probe fails, the kubelet automatically restarts the container. This probe is designed to remediate application-level faults such as deadlocks or unresponsive processes.
  • startupProbe: determines whether the application within a container has completed its initialization. Until the startup probe succeeds, the liveness and readiness probes remain disabled. This probe is particularly suitable for applications with lengthy startup times, such as Java Spring Boot services, as it prevents premature termination by the liveness probe during the initialization phase.

Configuration example:

...
containers:
- name: nginx
  image: nginx:alpine
  ports:
  - containerPort: 80
  # Readiness probe: Traffic is received only when the application is ready.
  readinessProbe:
    httpGet:
      path: /
      port: 80
    initialDelaySeconds: 5 # Delay in seconds before the probe starts
    periodSeconds: 10 # Interval in seconds for performing the probe
    failureThreshold: 3 # Number of consecutive failures before the probe is considered failed
  # Liveness probe: Restart the container if it is abnormal.
  livenessProbe:
    httpGet:
      path: /
      port: 80
    initialDelaySeconds: 15
    periodSeconds: 20
    failureThreshold: 3  # Increase this value to between 3 and 5 to prevent frequent container restarts caused by temporary fluctuations such as heavy load or GC pauses.
  # Startup probe: protects applications such as Java that take a long time to start.
  startupProbe: 
    httpGet:
      path: /
      port: 80
    failureThreshold: 30
    periodSeconds: 10
...

Graceful Lifecycle

When a pod is deleted, for example during a rolling update, node draining, or scale-in, Kubernetes sends a SIGTERM signal to the containers in the pod. If the container exits immediately, requests that are being processed may be interrupted, causing the client to receive an error response such as "Connection Refused." Configure preStop hooks and a graceful termination period so that the pod can deregister from load balancers first and the container can complete all cleanup operations before exiting.

Configuration example:

...
containers:
- name: nginx
  lifecycle:
    preStop:
      exec:
        command: ["/bin/sh", "-c", "sleep 30"] # Wait for 30 seconds to allow the load balancer's health checks to detect the terminating state and remove the backend.
terminationGracePeriodSeconds: 45   # The total grace period is 45 seconds, which must exceed the preStop sleep time.
...

Complete YAML Example

This example deploys four replicas of an application, integrating pod topology spread constraints (recommended), a PDB, health probes, and graceful termination to withstand both single-node failures and single-AZ outages.

# 1. PodDisruptionBudget ensures that at least two pods remain available during voluntary disruptions.
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: nginx-ha-pdb
spec:
  minAvailable: 2
  selector:
    matchLabels:
      app: nginx-ha
---
# 2. A Deployment integrates pod topology spread constraints, health probes, and graceful termination settings.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-ha
spec:
  replicas: 4
  selector:
    matchLabels:
      app: nginx-ha
  template:
    metadata:
      labels:
        app: nginx-ha
    spec:
      terminationGracePeriodSeconds: 45
      # Use pod topology spread constraints to evenly spread pods across AZs and nodes.
      topologySpreadConstraints:
      - maxSkew: 1
        topologyKey: topology.kubernetes.io/zone
        whenUnsatisfiable: DoNotSchedule
        labelSelector:
          matchLabels:
            app: nginx-ha
      - maxSkew: 1
        topologyKey: kubernetes.io/hostname
        whenUnsatisfiable: DoNotSchedule
        labelSelector:
          matchLabels:
            app: nginx-ha
      containers:
      - name: nginx
        image: nginx:alpine
        ports:
        - containerPort: 80
        # Graceful lifecycle
        lifecycle:
          preStop:
            exec:
              command: ["/bin/sh", "-c", "sleep 30"]
        # Probe settings
        readinessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 10
        livenessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 15
          periodSeconds: 20
        resources:
          requests:
            cpu: 250m
            memory: 256Mi
          limits:
            cpu: 500m
            memory: 512Mi
      imagePullSecrets:
      - name: default-secret

Verification and Testing

  1. Verify pod distribution.
    kubectl get pod -owide -l app=nginx-ha

    Inspect the NODE field in the pod list output. The pods should be distributed across multiple nodes and AZs.

    NAME                        READY   STATUS    RESTARTS   AGE   IP           NODE              ZONE
    nginx-ha-5b9f6c8d7c-2xk9l   1/1     Running   0          2m    10.0.0.132   192.168.5.112     az1
    nginx-ha-5b9f6c8d7c-4m7nq   1/1     Running   0          2m    10.0.1.133   192.168.5.252     az2
    nginx-ha-5b9f6c8d7c-7p3rd   1/1     Running   0          2m    10.0.0.9     192.168.5.179     az1
    nginx-ha-5b9f6c8d7c-9s5tv   1/1     Running   0          2m    10.0.2.45    192.168.5.8       az3
  2. Verify the PDB.
    kubectl get pdb nginx-ha-pdb

    Example output:

    NAME            MIN AVAILABLE   MAX UNAVAILABLE   ALLOWED DISRUPTIONS   AGE
    nginx-ha-pdb    2               N/A               2                     5m

    When you run kubectl drain or trigger a rolling update, the system ensures that at least two pods are available. If you attempt to interrupt the third pod, the operation will be blocked.

  3. Simulate a node failure by draining a node. Confirm that the pods are rescheduled elsewhere and that the total number of simultaneously unavailable pods does not exceed the limit defined by the PDB.

    For example, disable scheduling on and drain a node (for example, 192.168.5.112, where two pods are running).

    # 1. Disable scheduling on the node (to prevent new pods from being scheduled to it).
    kubectl cordon 192.168.5.112
    
    # 2. Drain the node (to evict pods, which is restricted by the PDB limit).
    kubectl drain 192.168.5.112 --ignore-daemonsets --delete-emptydir-data

    Check the pod distribution again.

    kubectl get pod -owide -l app=nginx-ha

    Example output:

    NAME                        READY   STATUS    RESTARTS   AGE   IP           NODE              ZONE
    nginx-ha-5b9f6c8d7c-4m7nq   1/1     Running   0          5m    10.0.1.133   192.168.5.252     az2
    nginx-ha-5b9f6c8d7c-9s5tv   1/1     Running   0          5m    10.0.2.45    192.168.5.8       az3
    nginx-ha-5b9f6c8d7c-b4x8w   1/1     Running   0           30s   10.0.1.142 192.168.5.252      az2  # New pod
    nginx-ha-5b9f6c8d7c-d6y9z   1/1     Running   0          30s   10.0.2.56    192.168.5.8       az3  # New pod
  4. Trigger a rolling update (for example, by changing the image tag).
    kubectl set image deployment/nginx-ha nginx=nginx:1.25.0

    Check whether the old pods wait for the duration specified by the preStop hook before terminating.

    kubectl get pod -w -l app=nginx-ha

    Expected output:

    NAME                         READY   STATUS        RESTARTS   AGE
    nginx-ha-5b9f6c8d7c-2xk9l   1/1     Running       0          10m
    nginx-ha-5b9f6c8d7c-4m7nq   1/1     Running       0          10m
    nginx-ha-5b9f6c8d7c-7p3rd   1/1     Running       0          10m
    nginx-ha-5b9f6c8d7c-9s5tv   1/1     Running       0          10m
    nginx-ha-7d8f9c6b5d-2abc   0/1     Pending       0          1s
    nginx-ha-7d8f9c6b5d-2abc   0/1     Pending       0          1s
    nginx-ha-7d8f9c6b5d-2abc   0/1     ContainerCreating   0          1s
    nginx-ha-7d8f9c6b5d-2abc   1/1     Running       0          5s        # The new pod is ready.
    nginx-ha-5b9f6c8d7c-2xk9l   1/1     Terminating   0          10m30s    # The old pod starts to be terminated (preStop sleep 30s will be executed).
    nginx-ha-5b9f6c8d7c-2xk9l   0/1     Terminating   0          11m       # The container will exit after 30s.
    nginx-ha-5b9f6c8d7c-2xk9l   0/1     Terminating   0          11m       # Removal completed.

    The old pod enters the Terminating state only after the new pod is started and in the Running state. The old pod stays in the Terminating state for at least 30 seconds (corresponding to preStop sleep 30s), providing a buffer for the load balancer to remove the backend and complete existing requests.

  5. Simulate an application fault. For example, manually disable the application's internal port to simulate an application fault. Confirm that the readiness probe removes the pod from service endpoints and that the liveness probe subsequently restarts the container.
    Assume that the default health check path of Nginx is /. Access the container and stop the Nginx service to simulate a fault.
    kubectl exec -it nginx-ha-5b9f6c8d7c-2xk9l -- /bin/sh
    # Run the following command in the container:
    kill -STOP 1   # Suspend the main process to make the probes fail.
    exit

    Observe the pod status change.

    kubectl get pod -w -l app=nginx-ha

    Expected output:

    NAME                        READY   STATUS    RESTARTS   AGE
    nginx-ha-5b9f6c8d7c-2xk9l   1/1     Running   0          15m
    nginx-ha-5b9f6c8d7c-2xk9l   0/1     Running   0          15m30s    # The readiness probe fails, and READY changes to 0/1 (traffic is removed).
    nginx-ha-5b9f6c8d7c-2xk9l   0/1     Running   1          16m       # The liveness probe fails, and the container is restarted (RESTARTS increases to 1).
    nginx-ha-5b9f6c8d7c-2xk9l   1/1     Running   1          16m30s    # After the container is restarted, the readiness probe is successful, and READY is restored to 1/1.

Node Pool HA

When using a node pool to deploy services, you can optimize the following aspects to improve availability and disaster recovery capabilities:

  • Node layer: Use the ECS group and AZ policies of the node pool for physical isolation.
  • Pod layer: Use affinity scheduling and pod topology spread constraints to ensure that replicas are evenly distributed onto different nodes.

For more information, see Implementing Node Pool-level HA.

Node Layer: Physical and AZ-level Isolation

The goal is to isolate the underlying infrastructure and prevent single-node and single-AZ faults.

  • Configuring physical host anti-affinity using an ECS group

    Create an anti-affinity ECS group on the ECS console and bind this group in the advanced settings of the CCE node pool. Nodes added to the node pool will be scheduled to different physical machines, preventing a single physical machine failure from affecting all nodes.

  • Creating a multi-AZ node pool for AZ-level anti-affinity

    When creating a node pool, select multiple AZs. Nodes will be then distributed across these AZs. If an AZ becomes faulty, nodes in other AZs can still ensure service continuity. This is the basis of the cross-AZ HA architecture.

Pod Layer: Fine-grained Distribution of Replicas Using Scheduling Policies

On the prerequisite of ensuring high availability and isolation of the underlying infrastructure, fully utilize the native scheduling capabilities of Kubernetes and use refined scheduling policies to evenly distribute service pod replicas, achieving high availability from underlying hardware to upper-layer applications.

  • Pod anti-affinity scheduling

    Use podAntiAffinity hard constraints to distribute multiple replicas of the same service to different nodes. Ensure that a single node runs at most one service pod replica. This prevents all service replicas from being scheduled to one node.

  • Pod topology spread constraints

    Compared with pod anti-affinity, pod topology spread constraints are more powerful and support multi-dimensional pod distribution balancing.

    • Key parameters:
      • topologyKey: specifies the topology domain. The node hostname and AZ are supported.
      • maxSkew: specifies the maximum allowed difference in the number of pods.
      • whenUnsatisfiable: specifies the policy when the condition is not met. The value can be DoNotSchedule (which rejects scheduling) or ScheduleAnyway (tries to schedule).
    • You can configure two constraints to ensure that pods are evenly distributed onto nodes and in AZs when Kubernetes schedules pods.

Stateful Storage

When stateful services are deployed in CCE across AZs, EVS disks cannot be attached across AZs. Common storage classes are prone to scheduling failures because the AZ of the PV does not match that of the pods. You can use the csi-disk-topology storage class and WaitForFirstConsumer (delayed binding) to schedule pods and then create EVS disks in the same AZ, which resolves cross-AZ scheduling conflicts.

For more information, see Implementing Cross-AZ Scheduling Using csi-disk-topology.

Background

EVS disks cannot be attached across AZs. For example, an EVS disk created in AZ 1 cannot be attached to a node in AZ 2.

  • The common storage class csi-disk uses the Immediate binding mode. When a PVC is created, a PV is created immediately, and the underlying EVS disk is generated.
  • When stateful services such as StatefulSets are deployed in a multi-AZ cluster, if an EVS disk is created in one AZ but the pod is scheduled to a node in another AZ, there will be a volume node affinity conflict. As a result, the pod enters the Pending state and fails to be scheduled.

    For example, a StatefulSet with four replicas is deployed in a cluster where three nodes are in three different AZs. Because the EVS disk cannot be attached across AZs, the storage volume of one pod is in an AZ that is different from the pod's scheduling target. As a result, the pod fails to be scheduled because the storage volume's AZ does not match the AZ of the node.

csi-disk-topology—A Storage Class with Delayed Binding

  • Binding mode: WaitForFirstConsumer is configured. When a PVC is created, a PV and an EVS disk are not generated immediately. The PVC remains in the Pending state.
  • Execution process: The pod is scheduled first, and the AZ of the node where the pod is running is identified. Then, an EVS disk and a PV are created in the AZ, and the PVC is bound to the PV. This ensures that the EVS disk and the pod node are in the same AZ and can be properly attached.

Key Differences Between csi-disk and csi-disk-topology

Storage Class

VolumeBindingMode

Behavior Characteristics

Applicable Scenarios

csi-disk

Immediate

A PV and an EVS disk are created when a PVC is created.

Single-AZ cluster

csi-disk-topology

WaitForFirstConsumer

Storage is created only after the pod scheduling is complete.

StatefulSets in a multi-AZ cluster

Comparison between the two storage classes:

  • csi-disk: After a PVC is created, it is directly bound to a PV, and storage is immediately allocated.
  • csi-disk-topology: After a PVC is created, it is in the Pending state, and the message "waiting for first consumer to be created before binding" is displayed. The storage is created in the AZ where the node is located only after the pod is scheduled to the node. This ensures that the storage and the pod are in the same AZ.

Verification

Symptom: When csi-disk is used for StatefulSets, all PVCs are successfully bound. However, some pods are in the Pending state because the AZ where the storage is located does not match the AZ where the node is running.

Solution: Change the value of storageClassName in volumeClaimTemplates to csi-disk-topology and deploy the StatefulSets again. After the deployment, all pods and PVCs are successfully created, and EVS disks are generated in the AZ where the pods are running. The scheduling conflict is eliminated.

If stateful services that use EVS disks are running in a multi-AZ cluster, csi-disk-topology is recommended to prevent scheduling failures caused by the mismatch between the AZ where the EVS disks are located and the AZ where the pod nodes are located.

FAQs

Do the PDB and Deployment Rolling Update Parameters maxSurge and maxUnavailable Conflict with Each Other?

No. The maxSurge and maxUnavailable parameters of a Deployment operate with the PDB. Kubernetes enforces the stricter of the two limits automatically.

How Long Should the preStop Hook Be Configured?

The duration depends on the average and maximum time required for the service to complete processing of in-flight requests. Typically, this ranges from 15 to 30 seconds. Additionally, the terminationGracePeriodSeconds should be set 5 to 10 seconds longer than the preStop duration to allow sufficient time for cleanup.

Should requiredDuringScheduling or preferredDuringScheduling Be Used for Pod Anti-affinity?

Use requiredDuringScheduling when the cluster has sufficient schedulable nodes and the replica count is less than or equal to the number of nodes or AZs, as this enforces strict distribution. Otherwise, use preferredDuringScheduling to prevent pods from remaining pending when hard constraints cannot be satisfied.

What Should the maxSkew Value Be in Pod Topology Spread Constraints?

Setting maxSkew to 1 achieves the strictest even distribution. When the number of replicas is not an integer multiple of the number of topology domains, this value ensures that the maximum difference in pod count between any two domains does not exceed one.

What Is tolerationSeconds? How Do I Set It?

tolerationSeconds defines the number of seconds that a pod can continue running on a node after a matching NoExecute taint is added to the node. After the specified time elapses, the pod will be evicted and rebuilt. It only works when the taint or toleration effect is set to NoExecute. By default, the duration is set to 300s for CCE clusters when nodes are disconnected or not ready. You can specify the duration when creating a workload.

How Do I Configure Resource Requests and Limits to Ensure the Stability of Pods Running Mission-critical Services?

For mission-critical services, you should set requests and limits to the same values (Guaranteed QoS) to prevent the pods from being terminated by the OOM Killer at the bottom layer when the node memory is insufficient.

You should use the Guaranteed QoS mode for pods running mission-critical services to ensure the stability. Specifically, set requests.memory and limits.memory to the same value, and set requests.cpu and limits.cpu to the same value.