Parameter |
Description |
---|---|
Required |
It specifies a rule that must be met in scheduling. It corresponds to requiredDuringSchedulingIgnoredDuringExecution in Kubernetes. You can click Add Rule to add multiple required rules. A pod will be scheduled on a node that meets any of the rules configured. |
Preferred |
It specifies a preference in scheduling. It corresponds to preferredDuringSchedulingIgnoredDuringExecution in Kubernetes. You can click Add Rule to add multiple preferred rules. The scheduler will try to enforce the rules but will not guarantee. If the scheduler cannot satisfy any one of the rules, the pod will still be scheduled. |
Parameter |
Description |
---|---|
Weight |
|
Label |
Node label. You can use the default label or customize a label. |
Operator |
The following relations are supported: In, NotIn, Exists, DoesNotExist, Gt, and Lt |
Value |
Tag value. Operators In and NotIn allow one or more label values. Values are separated with colons (;). Operators Exists and DoesNotExist are used to determine whether a label exists, and do not require a label value. If you set the operator to Gt or Lt for a label, the label value must be greater than or less than a certain integer. |
Operation |
You can click Delete to delete a selector. |
Add Selector |
A selector corresponds to matchExpressions in Kubernetes. You can click Add Selector to add multiple selectors for a scheduling rule. The rule is applied in scheduling only when all its selectors are satisfied. |
This section uses Nginx as an example to describe how to configure node affinity.
Prerequisites
A workload that uses the nginx container image has been deployed on a node.
Procedure
Set Label to kubernetes.io/hostname, add affinity nodes, and set the operator to In. Then, click OK.
YAML file of the workload with node affinity:
apiVersion: apps/v1 kind: Deployment metadata: name: nginx namespace: default spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - image: nginx imagePullPolicy: Always name: nginx imagePullSecrets: - name: default-secret affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - 192.168.6.174