All Products
Search
Document Center

Schedule pods to Virtual Kubelet

Last Updated: May 19, 2022

For a serverless Kubernetes (ASK) cluster, the entire cluster runs on an elastic container instance, so you do not need to schedule pods. For a Container Service for Kubernetes (ACK) cluster which uses both real nodes and virtual nodes, you can schedule pods to Virtual Kubelet, so that the pods can run on elastic container instances. This topic describes how to schedule pods to Virtual Kubelet.

Overview of scheduling methods

You can use one of the following methods to schedule pods to Virtual Kubelet.

Note

To use the following methods, you must modify existing resources. We recommend that you configure Elastic Container Instance Profile. Elastic Container Instance Profile provides the Elastic Container Instance Scheduler feature. When you use this feature, you can declare the pod or namespace labels to be matched in the eci-profile configuration file. If a pod has the declared labels, the pod is automatically scheduled to Elastic Container Instance. For more information, see Configure Elastic Container Instance Profile.

  • Configure pod labels

    If you have several pods that need to be scheduled to run on elastic container instances, you can add labels to the pods. Then, the pods run on elastic container instances in Virtual Kubelet.

  • Configure namespace labels

    If you have many pods that you want to run on elastic container instances, you can create a namespace and add a label to the namespace. Then, all pods in the namespace are scheduled to run on elastic container instances in Virtual Kubelet.

  • (Only for ACK Pro clusters) Configure Elastic Container Instance elastic scheduling policy

    Elastic Container Instance provides an elastic scheduling policy. When you deploy services, you can add annotations to declare that only the resources of real nodes or Virtual Kubelet are used, or when the resources of real nodes are insufficient, Elastic Container Instance resources are automatically used. This policy can meet different requirements for elastic resources in different scenarios.

  • (Not recommended) Other methods

    You can use other methods such as adding nodeSelector and tolerations fields to your pod configuration or specifying node names to schedule pods to Virtual Kubelet.

Method 1: Configure pod labels

You can add an alibabacloud.com/eci=true label to a pod to schedule the pod to run on elastic container instances.

Note

You can also add an eci=true label, but we do not recommend you to do this.

The following example shows the procedure on how to configure pod labels:

  1. Create a YAML configuration file for the pod that you want to create.

    vim test-pod.yaml

    An example of the content of test-pod.yaml:

    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx1
      labels: 
        alibabacloud.com/eci: "true" # Add a label.
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
  2. Create the pod.

    kubectl apply -f test-pod.yaml 

Method 2: Configure namespace labels

You can create a namespace and add an alibabacloud.com/eci=true label to the namespace. Then, all pods in the namespace are scheduled to run on elastic container instances.

Note

You can also add a virtual-node-affinity-injection=enabled label, but we do not recommend you to do this.

The following example shows the procedure on how to configure namespace labels:

  1. Create a namespace.

    kubectl create ns vk
  2. Add a label to the namespace.

    kubectl label namespace vk alibabacloud.com/eci=true
  3. Create a YAML configuration file for the pod that you want to create.

    vim test-pod.yaml

    An example of the content of test-pod.yaml:

    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
      namespace: vk # Specify the namespace to which you added a label in Step 2.
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
  4. Create the pod.

    kubectl apply -f test-pod.yaml 

Method 3: Configure the elastic scheduling policy of Elastic Container Instance

You can add annotations to pod metadata to declare the type of the elastic resources that you want to use. The configuration item is alibabacloud.com/burst-resource. Valid values of the configuration item:

  • eci: Elastic container instances are used when the resources on the real nodes of the cluster are insufficient.

  • eci_only: Only elastic container instances are used.

Notice

This method is suitable only for ACK Pro clusters whose Kubernetes version is 1.18 or later.

The following example shows the procedure on how to configure the elastic scheduling policy of Elastic Container Instance:

  1. Create the YAML configuration file to use for deployment.

    vim test-deployment.yaml

    An example of the content of test-deploymen.yaml:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      replicas: 4
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          name: nginx
          annotations:
            alibabacloud.com/burst-resource: eci # Specify the type of resource that you want to use.
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx
            resources:
              limits:
                cpu: 2
              requests:
                cpu: 2
  2. Create a deployment.

    kubectl apply -f test-deployment.yaml 

Other methods (Not recommended)

You can use other methods such as configuring the node selector and tolerations parameters or specifying node names to schedule pods to run on elastic container instances.

The following example shows the procedure on how to use other methods to schedule pods to run on elastic container instances:

  1. Prepare a YAML configuration file for the pod that you want to create.

    vim test-pod.yaml

    An example of the content of test-pod.yaml:

    • Configure nodeSelector and tolerations fields.

      apiVersion: v1
      kind: Pod
      metadata:
        name: nginx
      spec:
        containers:
        - image: nginx
          imagePullPolicy: Always
          name: nginx
        nodeSelector:
          type: virtual-kubelet
        tolerations:
        - key: virtual-kubelet.io/provider
          operator: Exists
    • Specify the node name

      apiVersion: v1
      kind: Pod
      metadata:
        name: nginx
      spec:
        containers:
        - image: nginx
          imagePullPolicy: Always
          name: nginx
        nodeName: virtual-kubelet 
  2. Create the pod.

    kubectl apply -f test-pod.yaml