All Products
Search
Document Center

Container Service for Kubernetes:Schedule pods to elastic container instances that are deployed as virtual nodes

Last Updated:Apr 21, 2025

When using a Container Service for Kubernetes (ACK) cluster, you might need to create many pods within a short period of time. If you choose to create Elastic Compute Service (ECS) instances for the pods, the scaling process is time-consuming. If you choose to reserve ECS instances, resources are wasted. With ACK virtual nodes, you can quickly schedule pods to elastic container instances without purchasing or managing ECS instances. This topic describes how to schedule pods to elastic container instances in an ACK managed cluster.

Scenarios

You can use elastic container instances to handle traffic spikes and reduce computing costs. Elastic container instances are suitable for the following scenarios:

  • Online services with obvious traffic fluctuations

    The traffic of online education, e-commerce, and other services usually has obvious traffic fluctuations. Using Elastic Container Instance-based pods can respond to traffic spikes more quickly and reduce the maintenance of fixed resource pools. This helps you reduce computing costs.

  • Non-continuous computing tasks

    Use Elastic Container Instance-based pods to run computing tasks. This way, you do not need to retain nodes. You only pay for the computing resources used during task execution. This reduces computing costs. The tasks include Spark and AI tasks.

Prerequisites

The Kubernetes version of the ACK cluster is 1.16 or later, and the region where the cluster is located supports elastic container instances.

Note

Check whether the region of the cluster is supported. For more information, see Regions and zones. Log on to the Elastic Container Instance console to activate the Elastic Container Instance service.

Procedure

Step 1: Deploy the ack-virtual-node component

Note

The following operations use an ACK managed cluster as an example. For an ACK dedicated cluster, you need to deploy the ack-virtual-node component on the Marketplace page. For more information, see Virtual nodes.

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, find the one you want to manage and click its name. In the left-side navigation pane, choose Operations > Add-ons.

  3. On the Add-ons page, find ACK Virtual Node on the Core Components tab, and click Install. Follow the instructions provided on the page.

    During installation, use the default vSwitch and security group of the cluster as the default configurations of the elastic container instance. For more information about how to modify the configurations, see Configure an eci-profile.

Step 2: Schedule pods to elastic container instances

Note

The following operations use the method of adding labels to pods or namespaces as an example to demonstrate how to schedule pods to virtual nodes for running on elastic container instances. For more information about the scheduling solutions, see Schedule a pod to a virtual node.

Add a label to a pod

If you need to schedule a specific pod to run on the elastic container instance, you can add a specific label to the pod, such as alibabacloud.com/eci: "true". The pod will be scheduled to an x86 architecture virtual node to run as an elastic container instance.

  1. Create a Deployment by using the following YAML file:

    kubectl create -f eci-pod.yaml

    The following is an example of the eci-pod.yaml file:

    Note

    The following YAML file specifies the specifications of the Elastic Container Instance-based pods by using the k8s.aliyun.com/eci-use-specs annotation. For more information about how to configure the specifications of Elastic Container Instance-based pods, see Specify the compute specification of an elastic container instance.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: test
      labels:
        app: test
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          name: test
          labels:
            app: nginx
            alibabacloud.com/eci: "true"             # Add a specific label to schedule the pod to the elastic container instance 
          annotations:
            k8s.aliyun.com/eci-use-specs: "2-4Gi"   # Specify that the Elastic Container Instance-based pod has 2 vCPUs and 4 GiB of memory
        spec:
          containers:
          - name: nginx
            image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
            ports:
            - containerPort: 80
  2. Verify whether the pod is running on a virtual node.

    kubectl get pod -o wide -l app=nginx

    The expected output is as follows. In the NODE field, you can see that the pod has been scheduled to a virtual node.

    NAME                    READY   STATUS    RESTARTS   AGE   IP            NODE                            NOMINATED NODE   READINESS GATES
    test-86f7fbc94f-g5m22   1/1     Running   0          38s   10.16.XX.XX   virtual-kubelet-cn-hangzhou-j   <none>           <none>
    test-86f7fbc94f-r4wcn   1/1     Running   0          38s   10.16.XX.XX   virtual-kubelet-cn-hangzhou-j   <none>           <none>
  3. View the details of the Elastic Container Instance-based pod.

    kubectl get pod <pod-name> -o yaml

    In the returned YAML file, you can obtain the ID of the corresponding elastic container instance based on the k8s.aliyun.com/eci-instance-id field and confirm the actual billing specifications of the Elastic Container Instance-based pod based on the k8s.aliyun.com/eci-instance-spec field.

Add a label to a namespace

If you need to schedule a category of pods to run on elastic container instances, you can create a namespace and add a specific label, such as alibabacloud.com/eci: "true". All pods in this namespace will be scheduled to x86 architecture virtual nodes to run as elastic container instances.

  1. Create a namespace named vk and add a specific label to the namespace.

    kubectl create ns vk
    kubectl label namespace vk alibabacloud.com/eci=true
  2. Create a Deployment in the vk namespace by using the following YAML file:

    kubectl create -f eci-namespace.yaml

    The following is an example of the eci-namespace.yaml file:

    Note

    The following YAML file specifies the specifications of the Elastic Container Instance-based pods by using the k8s.aliyun.com/eci-use-specs annotation. For more information about how to configure the specifications of Elastic Container Instance-based pods, see Specify the compute specification of an elastic container instance.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: test
      namespace: vk       # Specify a namespace with a specific label to schedule pods to elastic container instances
      labels:
        app: test
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          name: test
          labels:
            app: nginx
          annotations:
            k8s.aliyun.com/eci-use-specs: "2-4Gi"   # Specify that the Elastic Container Instance-based pod has 2 vCPUs and 4 GiB of memory
        spec:
          containers:
          - name: nginx
            image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
            ports:
            - containerPort: 80
  3. Verify whether the pod is running on a virtual node.

    kubectl get pod -o wide -l app=nginx -n vk

    The expected output is as follows. In the NODE field, you can see that the pod has been scheduled to a virtual node.

    NAME                   READY   STATUS    RESTARTS   AGE   IP            NODE                            NOMINATED NODE   READINESS GATES
    test-8f54bcfb5-86pvc   1/1     Running   0          14s   10.16.XX.XX   virtual-kubelet-cn-hangzhou-j   <none>           <none>
    test-8f54bcfb5-skvkg   1/1     Running   0          14s   10.16.XX.XX   virtual-kubelet-cn-hangzhou-j   <none>           <none>
  4. View the details of the Elastic Container Instance-based pod.

    kubectl get pod <pod-name> -o yaml -n vk

    In the returned YAML file, you can obtain the ID of the corresponding elastic container instance based on the k8s.aliyun.com/eci-instance-id field and confirm the actual billing specification of the Elastic Container Instance-based pod based on the k8s.aliyun.com/eci-instance-spec field.