All Products
Document Center

Deploy and use ack-kubernetes-elastic-workload in an ACK cluster

Last Updated: Sep 09, 2021

This topic describes how to deploy and use ack-kubernetes-elastic-workload in a Container Service for Kubernetes (ACK) cluster.


An ACK cluster is created, and a virtual node is deployed in the cluster.

Background information

Kubernetes provides elasticity at the scheduling layer for pods and at the resource layer for nodes. Kubernetes can use Horizontal Pod Autoscaler (HPA), Cron Horizontal Pod Autoscaler(CronHPA), and Vertical Pod Autoscaling (VPA) models to scale pods and use Cluster Autoscaler and Virtual Kubelet to scale nodes. The scheduling and resource layers are decoupled by pods. This mechanism ensures that responsibilities are segregated between these layers. However, after the layers are decoupled, simple scheduling policies must be separately configured for each layer and can be used in combination. This makes it impossible to implement finer-grained scheduling policies. In Kubernetes, pod is the minimum lifecycle management unit. The pods managed by traditional Kubernetes load controllers such as Deployments and StatefulSets share scheduling policies. Therefore, to control how to allocate a workload across different resources in a fine-grained manner, you can use ack-kubernetes-elastic-workload.

Deploy ack-kubernetes-elastic-workload

  1. Log on to the ACK console.

  2. In the left-side navigation pane, choose Marketplace > App Catalog.

  3. On the Alibaba Cloud Apps tab, find and click ack-kubernetes-elastic-workload.

    A large number of applications are displayed on the Alibaba Cloud Apps page. You can enter a keyword in the search box in the upper-right corner to search for ack-kubernetes-elastic-workload.

  4. In the Deploy section of the App Catalog - ack-kubernetes-elastic-workload page, select a cluster to deploy ack-kubernetes-elastic-workload and click Create.ack-kubernetes-elastic-workload 1

  5. Check whether ack-kubernetes-elastic-workload is deployed.

    1. In the left-side navigation pane, click Clusters.

    2. Click the ID of the cluster that you selected in the previous step.

    3. In the left-side navigation pane, choose Applications > Helm.

    4. Check whether ack-kubernetes-elastic-workload is in the Deployed state.Deploy ack-kubernetes-elastic-workload

Use an elastic workload

For example, capacity is planned for an application and that the application is expected to have up to four replicas to run on Elastic Compute Service (ECS) instances. Two replicas are retained during off-peak hours. If the number of replicas is greater than four, the extra replicas are scheduled to the virtual node. This prevents other applications on the ECS instances from being affected.

Kubernetes schedules workloads and manages the lifecycle of workloads. To implement the preceding scenario, you must perform the following operations:

  • Control how the scheduling policy changes when the number of replicas reaches a specific value.

  • Prioritize specific pods for lifecycle management.

This section describes how to use ack-kubernetes-elastic-workload to perform the preceding operations for an elastic workload.

  1. Create an application by using a Deployment.

    apiVersion: apps/v1 
    kind: Deployment
      name: nginx-deployment-basic
        app: nginx
      replicas: 2
          app: nginx
            app: nginx
          - name: nginx
            image: nginx:1.7.9 
            - containerPort: 80
              requests:    # If you want to use HPA for the application, you must specify requests.
                cpu: "500m"      
                memory: "1024Mi"  
  2. Define an elastic workload.

    kind: ElasticWorkload
      name: elasticworkload-sample
        name: nginx-deployment-basic
        kind: Deployment
        apiVersion: apps/v1
        min: min: 2        #The minimum number of replicas.
        max: max: 4        #The maximum number of replicas.
      replicas: 6
      - name: virtual-kubelet

    ack-kubernetes-elastic-workload is used in a similar manner as an HPA. ack-kubernetes-elastic-workload is deployed as an external add-on and does not affect your existing business.Deploy ack-kubernetes-elastic-workload 2

    You can use ack-kubernetes-elastic-workload to create elastic workloads. An elastic workload listens to a source workload, and can clone and generate replicas for elastic units based on the predefined scheduling policies. If the number of replicas in an elastic workload reaches the threshold, the numbers of replicas scheduled on the source workload and on the elastic unit are dynamically adjusted.

    Typically, an elastic workload consists of the following two parts:

    • sourceTarget: defines the type of the source workload and the range for the number of replicas.

    • elasticUnit: an array that defines the scheduling policy for the elastic unit. If you need to define scheduling policies for multiple elastic units, specify related parameters in the order shown in the template.

    In this example:

    • As defined in sourceTarget, the number of replicas for the source workload ranges from two to four. In this case, if the elastic workload has two to four replicas, replicas are scheduled to the source workload. If the number of replicas is greater than four, the extra replicas are scheduled to the elastic unit (Virtual Node virtual-kubelet).

    • In elasticUnit, the elastic unit is defined as the virtual-kubelet virtual node, which corresponds to the labels: scheduling policy.

  3. Check the deployment result.

    • View the status of the elastic workload.

      kubectl describe ew elasticworkload-sample

      A command output similar to the following one is returned. The value of Desired Replicas in the Status section indicates the number of replicas scheduled to the elastic unit:

      Name:         elasticworkload-sample
      Namespace:    default
      Labels:       <none>
      Annotations:  <none>
      API Version:
      Kind:         ElasticWorkload
        Creation Timestamp:  2021-05-21T01:53:58Z
        Generation:          4
        Managed Fields:
          API Version:
          Fields Type:  FieldsV1
          Manager:      Apache-HttpClient
          Operation:    Update
          Time:         2021-05-21T01:53:58Z
          API Version:
          Fields Type:  FieldsV1
          Manager:         manager
          Operation:       Update
          Time:            2021-05-21T01:56:45Z
        Resource Version:  8727
        Self Link:         /apis/
        UID:               c4a508aa-2702-4d17-ac25-e6a207c0761a
        Elastic Unit:
          Name:                    virtual-kubelet
        Replicas:                  6
        Source Target:
          API Version:  apps/v1
          Kind:         Deployment
          Max:          4
          Min:          2
          Name:         nginx-deployment-basic
        Elastic Units Status:
          Desired Replicas:  2
          Name:              nginx-deployment-basic-unit-virtual-kubelet
          Update Timestamp:  2021-05-21T01:56:45Z
        Replicas:            6
        Selector:            app=nginx
        Source Target:
          API Version:       apps/v1
          Desired Replicas:  4
          Kind:              Deployment
          Name:              nginx-deployment-basic
          Update Timestamp:  2021-05-21T01:56:45Z
        Type    Reason                 Age                  From             Message
        ----    ------                 ----                 ----             -------
        Normal  SourceUpdate           12m                  ElasticWorkload  Source Target scale from 2 to 4
        Normal  UnitCreation           12m                  ElasticWorkload  ElasticWorkloadUnit nginx-deployment-basic-unit-virtual-kubelet created
        Normal  ElasticWorkloadUpdate  9m27s (x9 over 12m)  ElasticWorkload  ElasticWorkload update
        Normal  UnitUpdate             9m27s (x8 over 12m)  ElasticWorkload  ElasticWorkloadUnit virtual-kubelet has been updated
    • View the status of pods.

      kubectl get pod -o wide

      A command output similar to the following one is returned. The output indicates that the elastic workload has cloned Deployments and pods, and that pod replicas in these Deployments are dynamically scheduled based on the predefined scheduling policy.

      NAME                                                           READY   STATUS    RESTARTS   AGE   IP              NODE                           NOMINATED NODE   READINESS GATES
      nginx-deployment-basic-5bf87f5f59-22jnw                        1/1     Running   0          16m     cn-beijing.          <none>           <none>
      nginx-deployment-basic-5bf87f5f59-gfp24                        1/1     Running   0          13m     cn-beijing.          <none>           <none>
      nginx-deployment-basic-5bf87f5f59-pw2zx                        1/1     Running   0          13m     cn-beijing.          <none>           <none>
      nginx-deployment-basic-5bf87f5f59-qvh7m                        1/1     Running   0          16m     cn-beijing.          <none>           <none>
      nginx-deployment-basic-unit-virtual-kubelet-65fb6f4cd7-48ssb   1/1     Running   0          13m   virtual-kubelet-cn-beijing-e   <none>           <none>
      nginx-deployment-basic-unit-virtual-kubelet-65fb6f4cd7-gjqhm   1/1     Running   0          13m   virtual-kubelet-cn-beijing-e   <none>           <none>

In addition, HPAs can be used for elastic workloads. Elastic workloads can dynamically adjust the number of replicas scheduled to each elastic unit based on the status of HPAs. For example, if the number of replicas in a Deployment changes from six to four for an elastic workload, the elastic workload preferentially reduces the replicas on elastic units. Sample code:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
  name: elastic-workload-demo
  namespace: default
    kind: ElasticWorkload
    name: elasticworkload-sample
  minReplicas: 2
  maxReplicas: 10
  - type: Resource
      name: cpu
        type: Utilization
        averageUtilization: 50

In conclusion, elastic workloads can generate Deployments by cloning and overriding scheduling policies. This allows you to manage scheduling policies. Elastic workloads can also adjust the number of replicas scheduled to source workloads and adjust the number of replicas scheduled to elastic units within the specified ranges. This allows you to prioritize specific pods for lifecycle management.