Workload-Node Affinity
Using the CCE Console
- When Creating a Deployment or Creating a StatefulSet, in the Scheduling Policies area on the Configure Advanced Settings page, choose Workload-Node Affinity and Anti-affinity > Affinity with Nodes > Add. Figure 1 Affinity with nodes
- Select the node on which you want to deploy the workload, and click OK.
If you select multiple nodes, the system automatically chooses one of them during workload deployment.
Using kubectl
This section uses an Nginx workload 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-node affinity. The following is an example YAML file for workload-node 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: nodeName #node's label key
operator: In
values:
- test-node-1 #node's label 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 Affinity Object.
- Set Object Type to Node and select the node where the workload is to be deployed. The workload will be deployed on the selected node. Figure 2 Adding an affinity object - Node
This method can be used to add, edit, or delete scheduling policies.
Last Article: Workload-AZ Anti-Affinity
Next Article: Workload-Node Anti-Affinity
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.