Schedule pods on ECI with virtual nodes

更新时间:
复制 MD 格式

Run pods on ECI in an ACK managed cluster to handle traffic spikes without managing ECS instances.

Usage notes

For kube-scheduler v6.11.0 or later, when more than 1,000 ACS or ECI pods are created concurrently by adding labels, upgrade to the latest version and enable the SchedulerBatchMoveEvents=true feature gate.

Use cases

ECI pods handle traffic spikes and reduce compute costs:

  • Online services with fluctuating traffic patterns

    Respond to traffic spikes faster, reduce resource pool maintenance, and lower compute costs.

  • Short-lived or batch computing tasks

    No dedicated node maintenance required. Pay only for compute resources used during execution, reducing costs for workloads such as Spark and AI jobs.

Prerequisites

The ACK cluster runs Kubernetes 1.16 or later in a region that supports ECI.

Note

Check supported regions in Regions and zones supported by ECI, then log on to the Elastic Container Instance console to activate ECI.

Procedure

Step 1: Deploy the ack-virtual-node component

Note

The following steps use an ACK managed cluster as an example. For an ACK dedicated cluster, deploy ack-virtual-node from the Marketplace page. 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 your cluster. In the left navigation pane, click Components and Add-ons.

  3. On the Add-ons page, click the Core Components tab, find ACK Virtual Node, and then click Install. Follow the on-screen instructions to complete the installation.

    During the installation, the default vSwitch and security group of the cluster are used as the initial ECI configuration parameters. To modify the parameters, you can update them by configuring an eci-profile.

Step 2: Schedule a pod to ECI

Note

These examples schedule a pod to ECI by labeling the pod or namespace. See Schedule a Pod to a virtual node for other methods.

Pod

Add the label alibabacloud.com/eci: "true" to a pod to schedule it to an x86-architecture virtual node as an ECI pod.

  1. Create a Deployment from the following YAML file.

    kubectl create -f eci-pod.yaml

    Example eci-pod.yaml:

    Note

    The k8s.aliyun.com/eci-use-specs annotation specifies the ECI pod compute specification. See Specify the compute specification of an ECI pod.

    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 this label to schedule the Pod to ECI. 
          annotations:
            k8s.aliyun.com/eci-use-specs: "2-4Gi"   # Specify 2 vCPUs and 4 GiB of memory for the ECI pod.
        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 Pod is running on a virtual node.

    kubectl get pod -o wide -l app=nginx

    Expected output. The NODE column indicates the 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 ECI pod.

    kubectl get pod <pod-name> -o yaml

    Check the k8s.aliyun.com/eci-instance-id annotation for the ECI instance ID and the k8s.aliyun.com/eci-instance-spec annotation for the compute specification used for billing.

Namespace

To run a category of pods on ECI, create a namespace and add the label alibabacloud.com/eci: "true". All pods in this namespace are scheduled to an x86-architecture virtual node as ECI pods.

  1. Create a Namespace named vk and add the required label to it.

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

    kubectl create -f eci-namespace.yaml

    Example eci-namespace.yaml:

    Note

    The k8s.aliyun.com/eci-use-specs annotation specifies the ECI pod compute specification. See Specify the compute specification of an ECI pod.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: test
      namespace: vk       # Specify the labeled Namespace to schedule Pods 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"   # Specify 2 vCPUs and 4 GiB of memory for the ECI pod.
        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 Pod is running on a virtual node.

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

    Expected output. The NODE column indicates the 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 ECI pod.

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

    Check the k8s.aliyun.com/eci-instance-id annotation for the ECI instance ID and the k8s.aliyun.com/eci-instance-spec annotation for the compute specification used for billing.