Workload-AZ Anti-Affinity
Using the CCE Console
- When Creating a Deployment or Creating a StatefulSet, in the Scheduling Policies area on the Configure Advanced Settings page, click next to Workload-AZ Affinity and Anti-affinity > Anti-affinity with AZs.
Figure 1 Scheduling policies
- Select an AZ in which the workload is ineligible to be deployed.
The created workload is not deployed on the selected AZ.
Using kubectl
This section uses Nginx as an example to describe how to create a workload using kubectl.
Prerequisites
The ECS where the kubectl client runs has been connected to your cluster. For details, see Connecting to a Cluster Using kubectl.
Procedure
When using kubectl to create a Deployment or using kubectl to create a StatefulSet, configure workload-AZ anti-affinity. The following is an example YAML file for workload-AZ anti-affinity.
apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: replicas: 1 selector: matchLabels: app: nginx strategy: type: RollingUpdate template: metadata: labels: app: nginx spec: containers: - image: nginx imagePullPolicy: Always name: nginx imagePullSecrets: - name: default-secret affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: failure-domain.beta.kubernetes.io/zone #node's label key operator: NotIn values: - az1 #node's key value
Setting the Object Type After Creating a Workload
- Log in to the CCE console and choose Workloads > Deployments or Workloads > StatefulSets in the navigation pane.
- Click the name of the workload for which you will add a scheduling policy. On the workload details page, choose Scheduling Policies > Add Simple Scheduling Policy > Add Anti-affinity Object.
Figure 2 Adding an anti-affinity object – Availability Zone
- Set Object Type to Availability Zone and select the AZ in which the workload is ineligible to be deployed. The workload will be constrained from being deployed in the selected AZ.
This method can be used to add, edit, or delete scheduling policies.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.