Schedule pods to elastic container instances by using virtual nodes

更新时间:
复制 MD 格式

ACK virtual nodes let you schedule pods directly to Elastic Container Instances (ECI) without provisioning or managing ECS nodes. Use virtual nodes when you need to scale quickly for traffic spikes or run short-lived compute jobs — ECI pods start on demand and you pay only for what you use.

This topic describes how to deploy the ack-virtual-node component in an ACK managed cluster and schedule pods to ECI.

Use cases

  • Traffic spikes: Online education and e-commerce services often experience sudden traffic surges. ECI-based pods scale up faster than ECS nodes and eliminate the need to maintain idle capacity.

  • Batch and AI workloads: For non-continuous jobs such as Spark and AI tasks, ECI removes the need to keep nodes running between executions. You pay only for compute resources consumed during task execution.

Prerequisites

Before you begin, make sure that:

Step 1: Deploy the ack-virtual-node component

These steps apply to an ACK managed cluster. For an ACK dedicated cluster, deploy ack-virtual-node from the Marketplace page instead. See Deploy the ack-virtual-node component.
  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of the cluster you want to manage. In the left navigation pane, click Add-ons.

  3. On the Component Management page, find ACK Virtual Node in the Core Components section, click Install, and follow the prompts. During installation, the cluster's default vSwitch and security group are used as the initial ECI configuration. To change these settings, update the eci-profile configuration.

Step 2: Schedule pods to ECI

Add the label alibabacloud.com/eci: "true" to a pod or a namespace to schedule it to a virtual node. Pods scheduled this way run on x86 architecture virtual nodes as ECI.

For additional scheduling options, see Schedule a pod to a virtual node.

Schedule a single pod to ECI

Add alibabacloud.com/eci: "true" directly to a pod's labels to schedule that pod to ECI.

  1. Create a deployment:

    This YAML uses the k8s.aliyun.com/eci-use-specs annotation to set the pod's compute specification. For more options, see Specify the compute specification of an elastic container instance.
    kubectl create -f eci-pod.yaml

    The following is an example eci-pod.yaml:

    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"             # Schedule this pod to ECI
          annotations:
            k8s.aliyun.com/eci-use-specs: "2-4Gi"   # 2 vCPUs, 4 GiB 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 that the pods are running on a virtual node:

    kubectl get pod -o wide -l app=nginx

    The NODE column shows the virtual node name when scheduling succeeds:

    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. Inspect the ECI pod:

    • k8s.aliyun.com/eci-instance-id — the ECI instance ID

    • k8s.aliyun.com/eci-instance-spec — the actual billing specification

    kubectl get pod <pod-name> -o yaml

    In the returned YAML:

Schedule all pods in a namespace to ECI

Add alibabacloud.com/eci: "true" to a namespace to automatically schedule all pods in that namespace to ECI. This avoids adding the label to each pod individually.

  1. Create a namespace named vk and label it:

    kubectl create ns vk
    kubectl label namespace vk alibabacloud.com/eci=true
  2. Create a deployment in the vk namespace:

    This YAML uses the k8s.aliyun.com/eci-use-specs annotation to set the pod's compute specification. For more options, see Specify the compute specification of an elastic container instance.
    kubectl create -f eci-namespace.yaml

    The following is an example eci-namespace.yaml:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: test
      namespace: vk       # All pods in this namespace are scheduled to ECI
      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"   # 2 vCPUs, 4 GiB 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 that the pods are running on a virtual node:

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

    The NODE column shows the virtual node name when scheduling succeeds:

    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. Inspect the ECI pod:

    • k8s.aliyun.com/eci-instance-id — the ECI instance ID

    • k8s.aliyun.com/eci-instance-spec — the actual billing specification

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

    In the returned YAML:

What's next

  • Schedule without changing pod or namespace YAML: Configure an eci-profile with custom selectors to automatically route matching pods to ECI. This approach requires no changes to your application manifests.

  • Customize ECI pod behavior: Use annotations for ECI pods to specify compute specs, enable image caching to speed up pod creation, assign IPv6 addresses, or expand temporary storage — without changing Kubernetes semantics.