All Products
Search
Document Center

Schedule pods to a VNode

Last Updated: May 19, 2022

If you have self-managed Kubernetes clusters in a data center or on an Alibaba Cloud Elastic Compute Service (ECS) instance, you use both real nodes and virtual nodes (VNodes). In this case, you can configure the nodeSelector and tolerations parameters, or specify the nodeName parameter to schedule pods to a VNode. Then, you can run the pods on the elastic container instances that are deployed in the VNode. This topic describes how to schedule pods to a VNode.

Introduction to scheduling methods

VNodes are equivalent to native Kubernetes nodes. If a Kubernetes cluster uses both real nodes and VNodes, you can use one of the following methods to schedule pods to a VNode:

Note

To use the following methods, you must modify existing resources. These modifications may cause vulnerabilities in your system. We recommend that you configure ECI Profile. ECI Profile provides the ECI Scheduler feature. When you use this feature, you can declare the pod label or namespace label to be matched in eci-profile. If a pod has the declared label, the pod is automatically scheduled to the elastic container instance. For more information, see Configure an ECI Profile to orchestrate pods.

  • Configure the nodeSelector and tolerations parameters

    By default, VNodes are configured with labels and taints. Therefore, you can configure nodeSelector and tolerations to schedule pods to VNodes and then run the pods on the elastic container instances that are deployed in the VNodes.

  • Specify the nodeName parameter

    You can specify the nodeName parameter to schedule pods to a VNode and then run the pods on the elastic container instances that are deployed in the VNode.

Method 1: Configure the nodeSelector and tolerations parameters

By default, VNodes are configured with labels and taints, as shown in the following code.

...
  labels:
    k8s.aliyun.com/vnode: "true"
...
  taints:
  - effect: NoSchedule
    key: k8s.aliyun.com/vnode
    value: "true"

Therefore, you can configure the nodeSelector and tolerations parameters to schedule pods to VNodes and then run the pods on the elastic container instances that are deployed in the VNodes. Perform the following operations:

  1. Save the following content as the deploy-vnode-test 1.yaml file.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vnode-nginx-test1
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: uid
      template:
        metadata:
          labels:
            app: uid
        spec:
          nodeSelector:     # Configure nodeSelector.
            k8s.aliyun.com/vnode: "true"
          tolerations:      # Configure tolerations.
          - key: k8s.aliyun.com/vnode
            operator: "Equal"
            value: "true"
            effect: "NoSchedule"
          containers:
          - name: nginx
            image: registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx:1.14.2
  2. Create a Deployment.

    kubectl apply -f deploy-vnode-test1.yaml

Method 2: Specify the nodeName parameter

You can specify the nodeName parameter to schedule pods to a VNode. Perform the following operations:

  1. Run the following command to query VNodes.

    kubectl get nodes

    Obtain the VNode name from the command output. By default, the name format of a VNode is <region>.<VNode ID>. The following code shows a sample output.

    NAME                                    STATUS   ROLES                  AGE    VERSION
    cn-hangzhou.vnd-2ze2qhf8lmp5kgsx****    Ready    agent                  132m   v1.20.6
    k8s-master                              Ready    control-plane,master   169m   v1.20.6
  2. Save the following content as the deploy-vnode-test2.yaml file.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vnode-nginx-test2
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: uid
      template:
        metadata:
          labels:
            app: uid
        spec:
          containers:
          - name: nginx
            image: registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx:1.14.2
          nodeName: cn-hangzhou.vnd-2ze2qhf8lmp5kgsx****   # Specify the VNode name.
  3. Create a Deployment.

    kubectl apply -f deploy-vnode-test2.yaml