VKE provides the ResourcePolicy scheduling policy, which allows you to specify a custom ResourcePolicy to set the order in which pods of a workload are flexibly scheduled to different types of nodes, such as subscription ECS instances, pay-as-you-go ECS instances, and virtual nodes. This topic describes how to configure custom ResourcePolicies to achieve ResourcePolicy scheduling.
Prerequisites
- The scheduler-plugin add-on has been installed in the target cluster and ResourcePolicy scheduling has been enabled. For detailed operations, see scheduler-plugin add-on.
tip
To use ResourcePolicy scheduling when Volcengine Container Instance (VCI) is used, make sure that a cluster related to VCI workloads has been created, the scheduler-plugin add-on has been installed in the cluster, and ResourcePolicy scheduling is enabled for the cluster. For VCI-related cluster operations, see Connecting to VCI. - When you use this capability in VCI workloads, we recommend that you enable the VCI inventory-aware scheduling feature. For detailed operations, see VCI inventory-aware scheduling.
Usage limits
- The ResourcePolicy scheduling feature is only available in clusters of the following Kubernetes versions. If the cluster version does not meet the requirements, upgrade the cluster version. For details, see Upgrading clusters.
- This feature cannot be used with pod-deletion-cost of Kubernetes at the same time. For information about pod-deletion-cost, see pod-deletion-cost.
- When you create a ResourcePolicy, make sure that the scheduled pods in the target namespace are not managed by the ResourcePolicy. Otherwise, the scheduled pods will be preferentially scaled in.
- After you modify an existing ResourcePolicy, scheduled pods will be scaled in according to the order of the original ResourcePolicy and newly added pods will be scaled in according to the order of the updated ResourcePolicy.
- Only Deployments support reverse scale-in through ResourcePolicies.
tip
Reverse scale-in: When a workload for which a ResourcePolicy is configured is being scaled in, the resource pool with the lowest priority specified in the ResourcePolicy will be scaled in first.
Procedure
Specify the priority of elastic resources in a ResourcePolicy.
warning
- A ResourcePolicy only applies to the pods that are related to all workloads with the specified label in the namespace of the ResourcePolicy.
- The resource pool mentioned below is not the node pool defined in VKE. The resource pool is the collection of all nodes in a cluster that meet a specific filter condition.
- For example, vci-pool in the following content is the collection of nodes in the current cluster that meet the type=virtual-kubelet condition.
The following table describes key parameters.
Examples
This topic provides an example of how to create a ResourcePolicy and define the priority of elastic resources in the following scenario.
Your cluster contains a fixed number of ECS resources, which means that autoscaling is not configured for the node pool where the nodes are located. Your cluster also contains VCI resources. To reduce resource usage costs when you deploy a workload, such as Deployment, in the cluster, you need to deliver the following results:
- Deployed pods are preferentially scheduled to the fixed ECS resources. When the ECS resources are insufficient, the elastic VCI resources are used as supplementary resources.
- During scale-in, pods on the VCI resources are preferentially deleted to release the VCI resources. Then, pods on the ECS resources are deleted to release the ECS resources.
This method primarily applies to workloads with steady and sustained traffic, which occasionally experience sudden traffic spikes. Fixed ECS resources can be used to handle long-term stable traffic and the quick autoscaling capability of VCI can be used to handle sudden traffic spikes. For more sample scenarios, see the Sample scenarios section of this topic. Step 1: (Optional) Create a cluster and enable ResourcePolicy scheduling
If you have an available cluster, install the scheduler-plugin add-on in the cluster, and enable ResourcePolicy scheduling, you can skip this step.
- In the left navigation bar of the VKE console, click Cluster. On the page that appears, click Create cluster.
- In the Create cluster dialog box, click Create now in the Custom managed clusters section.
- On the Create cluster page, specify cluster parameters based on the on-screen prompts and your business requirements.
- Specify some parameters based on the following descriptions. For detailed configuration instructions for other parameters, see Creating managed clusters.
- In this example, both ECS and VCI resources exist in the cluster. Therefore, select VPC-CNI for the Network model parameter in the Cluster configuration step.
- In the Addon configuration step, find the scheduler-plugin card and click Configuration. In the scheduler-plugin parameter configuration dialog box, enable ResourcePolicy scheduling and configure the scheduling weight.
- Confirm the configurations and then click Confirm to create the cluster.
Step 2: Create a ResourcePolicy
- Create a YAML file for the ResourcePolicy. The following vke-resourcepolicy-nginx.yaml file serves as an example:
- Run the following command to create the ResourcePolicy.
Step 3: Create a workload
This topic provides an example of how to create a Deployment. For more workload-related operations, see Workloads. - Create a YAML file for the Deployment. The following demo-nginx.yaml file serves as an example:
- Run the following command to create the Deployment.
Step 4: View the scheduling result
- Run the following command to view the scheduling result.
- The expected output is as follows: Two pods are scheduled to ECS resources, and the remaining three pods are scheduled to VCI resources.
- (Optional) View the status of resource release when a pod is being scaled in.
- Run the following command to reduce the number of pods in the Deployment to 3, which is the value of the replicas parameter.
- View the scheduling result.
- The expected output is as follows: Two pods on VCI resources are scaled in first to release VCI resources.
Sample scenarios
Scenario 1: VCI resources and automatically scaled ECS resources
- VCI resources are preferentially used when both VCI resources and automatically scaled ECS resources exist in the target namespace of the cluster. When the VCI resource quota is insufficient, pods will be scheduled to the ECS resources, and autoscaling will be triggered to scale out the ECS resource pool. This method mainly applies to workloads such as batch jobs that experience sudden, high resource usage. You do not need to maintain fixed ECS resource costs, and VCI is preferentially used to obtain cost-effective elastic resources. When the VCI capacity is insufficient, ECS resources can be autoscaled to ensure sufficient resource supply.
- Configuration description
- Configure the virtual node that corresponds to the VCI resources as the first subset.
- We recommend that you specify the maxReplicas field under subset to prevent the VCI ResourceQuota from being exhausted. The value of the maxReplicas field can be estimated based on the VCI resource quota and the resource requirements of pods.
- Configure the node pool that corresponds to the ECS resources as the second subset.
- You need to specify the maxReplicas field under subset to control the maximum number of ECS resources that can be used. The value of the maxReplicas field can be estimated based on the ECS resource capacity and the resource requirements of pods.
- Set the whenNotReachMax field under subset to DoNotSchedule. In this way, when ECS resources are insufficient, scheduled pods will be in the Pending state for a short period of time, and then autoscaling will be triggered to scale out the ECS resource node pool.
Scenario 2: Schedule pods to ECS resources and VCI resources by proportion
- Schedule the pods in the workload to ECS resources and VCI resources based on the specified ratio to maintain the balance between fixed resources and elastic resources. This method is applicable when the workload is being switched from ECS resources to elastic VCI resources. You can use this method to gradually switch the workload by adjusting the scheduling ratio.
- Configuration description
- Configure the node pool that corresponds to the ECS resources as the first subset.
- You need to specify the maxReplicasRatio field under subset to schedule pods to the ECS resources based on the specified ratio.
- Configure the virtual node that corresponds to the VCI resources as the second subset.
- You need to specify the maxReplicasRatio field under subset to schedule pods to the VCI resources based on the specified ratio. We recommend that you keep the sum of the ratio thresholds of the maxReplicasRatio field for all subsets to 1.
warning
A deviation exists for the calculation of the scheduling ratio when a small number of pods exist. We do not recommend that you specify both maxReplicasRatio and whenNotReachMax: DoNotSchedule. Otherwise, some pods may be in the Pending state unexpectedly.