When you deploy Services in a Container Service for Kubernetes (ACK) cluster, you can configure tolerations and node affinity to enable the scheduler to use only Elastic Compute Service (ECS) instances or elastic container instances, or allow the scheduler to automatically apply for elastic container instances when ECS instances are insufficient. You can configure different scheduling policies to scale resources in different scenarios.
Terms
Taint: By default, the
virtual-kubelet.io/provider=alibabacloud:NoSchedule
taint is added to all virtual nodes in an ACK cluster in case elastic container instances are used without your approval.Toleration: Tolerations apply to pods. Tolerations allow the scheduler to schedule pods to nodes with matching taints. In an ACK cluster, you need to configure the following toleration to tolerate the
virtual-kubelet.io/provider=alibabacloud:NoSchedule
taint. This way, pods can be scheduled to elastic container instances.tolerations: - key: virtual-kubelet.io/provider operator: Equal value: alibabacloud effect: NoSchedule
Node affinity: Node affinity is a property of pods that attracts pods to a set of nodes either as a preference or a hard requirement.
Prerequisites
The ack-virtual-node component is installed in an ACK Pro cluster. For more information, see Use Elastic Container Instance in ACK clusters.
The virtual node-based pod scheduling policy is enabled for the ACK Pro cluster. For more information, see Enable the virtual node-based pod scheduling policy for an ACK cluster.
Procedure
The following sections introduce how to use taints, tolerations, and node affinity to schedule pods based on the following policies:
Use only elastic container instances: The ECS instances in the cluster are not used.
Preferably use ECS instances: Elastic container instances are used only when the ECS instances in the cluster are insufficient.
Use only ECS instances: Only the ECS instances in the cluster are used.
Use only elastic container instances
Preferably use ECS instances
If you want to prioritize an ECS node pool that consists of nodes with the label_1=key_1 label during pod scheduling and configure the scheduler to schedule pods to virtual nodes when the node pool cannot provide sufficient ECS nodes, use the following deployment.
The logical relation among multiple node affinity rules in nodeSelectorTerms is OR. A pod is scheduled to a node if the pod matches one of the rules.
The logical relation among multiple expressions in the matchExpressions field of nodeSelectorTerms is AND. A pod is scheduled to a node only if the pod matches all expressions.
The node affinity setting preferredDuringSchedulingIgnoredDuringExecution cannot guarantee that pods are scheduled to elastic container instances only when ECS instances are insufficient. Pods may be scheduled to elastic container instances even if there are sufficient ECS instances.
Use only ECS instances
To avoid using elastic container instances which are pricy, the following taint is added to virtual nodes by default.
virtual-kubelet.io/provider=alibabacloud:NoSchedule
If you do not configure a toleration to tolerate the taint, pods are scheduled only to ECS instances.