All Products
Search
Document Center

Schedule pods to Elastic Container Instance

Last Updated: Sep 08, 2021

For Serverless Kubernetes (ASK) clusters, the entire clusters run on Elastic Container Instance, so you do not need to schedule pods to Elastic Container Instance. For Container Service for Kubernetes (ACK) clusters or self-managed Kubernetes clusters where ECI and regular nodes are used, you can schedule pods to elastic container instances that are deployed on virtual nodes. This topic describes how to schedule a pod to Elastic Container Instance.

Overview of scheduling methods

When you use Elastic Container Instance together with regular nodes, you can use the following methods to schedule a pod to Elastic Container Instance:

Note

To use the following methods, you must modify existing resources. These modifications may cause vulnerabilities in your system. We recommend that you configure Elastic Container Instance Profile. Elastic Container Instance Profile provide 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 the elastic container instances that are connected in the virtual node.

  • 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 the elastic container instances in the virtual node.

  • Configure Elastic Container Instance elastic scheduling

    Elastic Container Instance elastic scheduling is an elastic scheduling policy provided by Alibaba Cloud. When you deploy services, you can add annotations to declare that only the resources of regular nodes or virtual nodes are used, or when the resources of regular nodes are insufficient, Elastic Container Instance resources are automatically used. This policy can be used to meet the different requirements for elastic resources in different scenarios.

  • (Not recommended) Other methods such as configuring the node selector and tolerations and specifying a node name

    When Virtual Kubelet exists in a Kubernetes cluster, you can schedule pods to Virtual Kubelet by configuring the node selector and tolerations or specifying a node name. Then, Virtual Kubelet creates elastic container instances to run the pods.

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 the YAML configuration file of the pod.

    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 a 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 the YAML configuration file of the pod.

    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 a pod.

    kubectl apply -f test-pod.yaml 

Method 3: Configure Elastic Container Instance elastic scheduling

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 regular nodes of the cluster are insufficient.

  • eci_only: Only elastic container instances are used.

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

  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 # This annotation specifies 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 

(Not recommended) Other methods

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

The following example shows the procedure on how to use other methods to schedule pods to Elastic Container Instance:

  1. Create the YAML configuration file of the pod.

    vim test-pod.yaml

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

    • Configure node selector and tolerations.

      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 a pod.

    kubectl apply -f test-pod.yaml