Achieve container scaling in seconds by using ack-autoscaling-placeholder

Updated at:

If your workloads must start quickly without waiting for node resources, use the ack-autoscaling-placeholder add-on. It provides a buffer for node auto scaling. When node resources are insufficient, the actual workload preempts the reserved resources and starts immediately, and node auto scaling then scales out the cluster.

Workflow

image

Prerequisites

  • Node auto scaling is enabled for the Container Service for Kubernetes (ACK) cluster, and an elastic node pool is configured. For more information, see Enable node autoscaling.

  • A node label is set on the elastic node pool by using the Node Labels configuration item. The label schedules workloads to the specified node pool, which makes the result easy to verify. For more information, see Create and manage node pools.

    The procedure in this topic uses the demo=yes label as an example.

Step 1: Deploy the ack-autoscaling-placeholder add-on and create a placeholder workload

ack-autoscaling-placeholder provides a buffer for node auto scaling, which allows cluster nodes to be over-provisioned and pre-warmed. This ensures that workloads scale out quickly without waiting for nodes to be created and added to the cluster.

Important

This workflow commits billable resources:

  • Each placeholder replica reserves the requested CPU and memory on a running ECS instance. The reserved capacity is billed whether or not an actual workload consumes it.

  • When an actual workload preempts a placeholder, the resulting Pending placeholder triggers node auto scaling to add ECS instances, which are billed at the instance prices of the node pool.

  • The total reserved capacity equals the requests of a single replica multiplied by replicaCount. A larger replicaCount multiplies the standing cost.

  • To stop the cost, set replicaCount to 0, or uninstall the ack-autoscaling-placeholder add-on.

For the pricing of the resources that this workflow uses, see ECS billing overview and Billing overview.

  1. Log on to the ACK console. In the left navigation pane, click Marketplace > Marketplace.

  2. On the App Catalog tab, search for ack-autoscaling-placeholder, and then click ack-autoscaling-placeholder.

  3. On the ack-autoscaling-placeholder page, click Deploy.

  4. On the Parameters tab, replace the Parameter content with the following YAML sample.

    Important

    Set resources.requests of the placeholder workload to the allocatable resources of the target node, not the total capacity of the node. Each node reserves resources for kubelet, the operating system, and kube-proxy.

    To check the allocatable resources, run kubectl describe node <node-name> and view the values under Allocatable.

    View the YAML sample

    nameOverride: ""
    fullnameOverride: ""
    ##
    priorityClassDefault:
      enabled: true
      name: default-priority-class   # The default priority is low.
      value: -1
    ##
    deployments:
       - name: ack-place-holder
         replicaCount: 1
         containers:
           - name: placeholder
             image: registry-vpc.cn-shenzhen.aliyuncs.com/acs/pause:3.1
             pullPolicy: IfNotPresent
             resources:
               requests:
                 cpu: 4            # Reserves 4 vCPUs and 8 GiB of memory.
                 memory: 8Gi
         imagePullSecrets: {}
         annotations: {}
         nodeSelector:        # Node selector. Must match the labels of the elastic node pool.
           demo: "yes"  
         tolerations: []
         affinity: {}
         labels: {}

    In the creation panel, complete the configuration as prompted, and then click OK.

    After the application is created, on the Applications > Helm page, the application status is Deployed.

Step 2: Create the actual workload's PriorityClass

  1. Create a file named priorityClass.yaml with the following YAML sample.

    apiVersion: scheduling.k8s.io/v1
    kind: PriorityClass
    metadata:
      name: high-priority
    value: 1000000       # The priority value. It must be higher than the default priority of the placeholder pod in the previous step.
    globalDefault: false
    description: "High-priority class for production workloads only."
    Important
    • A PriorityClass value must be an integer in the range of -2147483648 to 1000000000. Larger values are reserved for the built-in PriorityClasses of critical system pods.

    • The value of the PriorityClass of the actual workload must be higher than the value of the placeholder PriorityClass (-1 in this topic). Otherwise, the actual workload cannot preempt the placeholder.

    • Keep the placeholder priority above the expendable pod priority threshold of node auto scaling. If it falls below the threshold, node auto scaling ignores Pending placeholder pods, no scale-out is triggered, and the pre-warmed buffer is never replenished.

  2. Deploy the PriorityClass of the actual workload.

    kubectl apply -f priorityClass.yaml

    Expected output:

    priorityclass.scheduling.k8s.io/high-priority created

Step 3: Create the actual workload

  1. Create a file named workload.yaml with the following YAML sample.

    View the YAML sample

    apiVersion: apps/v1 
    kind: Deployment
    metadata:
      name: placeholder-test
      labels:
        app: nginx
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          nodeSelector:    # Node selector. Must match the labels of the elastic node pool.
            demo: "yes"
          priorityClassName: high-priority     # Set this to the name of the PriorityClass configured in the previous step.
          containers:
          - name: nginx
            image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6 
            ports:
            - containerPort: 80
            resources:       
              requests:      
                cpu: 3         # The resource requests of the actual workload. Must not exceed the cpu request of the placeholder workload (4).
                memory: 5Gi    # Must not exceed the memory request of the placeholder workload (8Gi).
    Note

    If the cpu or memory request of the actual workload exceeds the request of the placeholder workload, the actual workload does not fit into the reserved resources, cannot start on the node where the placeholder runs, and the seconds-level startup that this topic describes does not occur.

  2. Deploy the actual workload.

    kubectl apply -f workload.yaml

    Expected output:

    deployment.apps/placeholder-test created

Verify the result

  1. After the placeholder workload ack-place-holder is created, the pod status is Running.

  2. When the actual workload is deployed, the high-priority PriorityClass allows it to preempt the resources reserved by the placeholder workload and start quickly. The pod of the placeholder workload is then evicted and stays in the Pending state because node resources are insufficient.

    • The actual workload placeholder-test is quickly deployed on the node where the placeholder workload runs.

      The pod status is Running, and the number of restarts is 0, which confirms that the workload is running as expected on the target node.

    • The placeholder workload is evicted and enters the Pending state.

      The pod fails to be scheduled because of 0/5 nodes are available: 1 Insufficient cpu, which indicates that no available node in the cluster meets the CPU resource requests.

  3. Because node auto scaling is enabled for the node pool, insufficient node resources trigger a scale-out. The placeholder workload is then scheduled to the newly scaled-out node, and its status is Running.

Next steps

To achieve elastic scale-out across multiple zones in high-availability scenarios, see Enable rapid multi-zone auto scaling.