All Products
Search
Document Center

Elastic Container Instance:Schedule pods to an x86-based virtual node

Last Updated:Mar 12, 2024

For Container Service for Kubernetes (ACK) Serverless clusters, all pods run on default x86-based virtual nodes without the need to be scheduled. For ACK clusters that use Elastic Compute Service (ECS) instances on real nodes and elastic container instances in virtual nodes, pods are scheduled to real nodes by default. You can schedule pods to virtual nodes based on your business requirements. This topic describes how to schedule pods in an ACK cluster to an x86-based virtual node.

Overview of scheduling methods

You can use one of the following methods to schedule pods to an x86-based virtual node.

Note

To use the following methods, you must modify existing resources. The modification may introduce vulnerabilities into your system. We recommend that you configure an eci-profile to use the ECI Scheduler feature. When you use the feature, you can specify the namespace or pod labels that you want to match in the eci-profile. Pods that have the specified labels are automatically scheduled to run on Elastic Container Instance. For more information, see Configure an eci-profile.

  • Configure pod labels

    If you want to schedule a small number of pods to run as elastic container instances, you can add specific labels to the pods. Then, the pods run on the x86-based virtual node.

  • Configure namespace labels

    If you want to schedule a class of pods to run as elastic container instances, you can create a namespace and add a specific label to the namespace. Then, all pods in the namespace run on the x86-based virtual node.

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

    Alibaba Cloud allows you to configure an Elastic Container Instance-based elastic scheduling policy. When you deploy Services, you can add annotations to specify that only the resources on real nodes or virtual nodes are used, or when the resources on real nodes are insufficient, the resources on virtual nodes are automatically used. The policy can meet resource scaling requirements in different scenarios.

  • (Not recommended) Other methods

    By default, labels and taints are configured for x86-based virtual nodes. You can configure the nodeSelector and tolerations fields for pods to schedule the pods to run on x86-based virtual nodes. You can also specify the nodeName field to schedule pods to run on x86-based virtual nodes.

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 Instance.

Note

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

Procedure:

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

    vim test-pod.yaml

    Sample test-pod.yaml file.

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

    kubectl create -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 Instance.

Note

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

Procedure:

  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

    Sample test-pod.yaml file.

    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
      namespace: vk  # Specify the namespace to which you added a label in Step 2.
    spec:
      containers:
      - image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
        imagePullPolicy: Always
        name: nginx
  4. Create pods.

    kubectl create -f test-pod.yaml 

Method 3: Configure an Elastic Container Instance-based elastic scheduling policy

You can add the alibabacloud.com/burst-resource annotation to the metadata in the configuration file of a pod to specify the type of the resources that you want to use in elastic scheduling. Valid values of the annotation:

  • eci: Elastic Container Instance is used when the resources on the real nodes of the cluster are insufficient.

  • eci_only: Only Elastic Container Instance is used.

Important

You can use this method only for ACK Pro clusters that run Kubernetes 1.18 or later. For more information, see Use Elastic Container Instance-based scheduling.

Procedure:

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

    vim test-deployment.yaml

    Sample test-deployment.yaml file.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          name: nginx
          annotations:
            alibabacloud.com/burst-resource: eci  # Specify the type of resources that you want to use in elastic scheduling.
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
            resources:
              limits:
                cpu: 2
              requests:
                cpu: 2
  2. Create the Deployment.

    kubectl create -f test-deployment.yaml 

(Not recommended) Other methods

You can use other methods such as configuring the nodeSelector and tolerations fields or specifying the nodeName field to schedule pods to run on Elastic Container Instance.

Procedure:

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

    vim test-pod.yaml

    Sample test-pod.yaml file

    • Configure the nodeSelector and tolerations fields.

      apiVersion: v1
      kind: Pod
      metadata:
        name: nginx
      spec:
        containers:
        - image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
          imagePullPolicy: Always
          name: nginx
        nodeSelector:     # Configure nodeSelector.
          type: virtual-kubelet
        tolerations:      # Configure tolerations.
        - key: virtual-kubelet.io/provider
          operator: Exists
    • Specify the nodeName field.

      apiVersion: v1
      kind: Pod
      metadata:
        name: nginx
      spec:
        containers:
        - image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
          imagePullPolicy: Always
          name: nginx
        nodeName: virtual-kubelet-cn-beijing-g # Specify a node name
      .
  2. Create pods.

    kubectl create -f test-pod.yaml