Manage HPA elastic policies with the saectl tool

更新时间:
复制 MD 格式

SAE elastic policies map to the Kubernetes HorizontalPodAutoscaler (HPA) resource type. Use the saectl tool to create, view, update, and delete elastic policies for your applications.

Prerequisites

Before you begin, ensure that you have:

Manage elastic policies

Create an elastic policy

  1. Create a file named hpa.yaml with the following configuration. For a description of each field, see K8s YAML configuration reference.

    apiVersion: autoscaling/v2
    kind: HorizontalPodAutoscaler
    metadata:
      annotations:
        sae.aliyun.com/alias: test-app        # Optional: nickname for the elastic policy
        sae.aliyun.com/enabled: "true"         # Optional: enable or disable the policy
      name: metric-test-app                    # Fixed format: metric-${application_name}
      namespace: default
    spec:
      behavior:                                # Optional: scaling behavior
        scaleDown:
          policies:
          - periodSeconds: 15                  # Fixed by SAE, do not modify
            type: Pods                         # Fixed by SAE, do not modify
            value: 10                          # Scale-in step size
          stabilizationWindowSeconds: 200
        scaleUp:
          policies:
          - periodSeconds: 15                  # Fixed by SAE, do not modify
            type: Pods                         # Fixed by SAE, do not modify
            value: 5                           # Scale-out step size
          stabilizationWindowSeconds: 100
      maxReplicas: 8
      metrics:
      - resource:
          name: cpu
          target:
            averageUtilization: 80
            type: Utilization
        type: Resource
      - resource:
          name: memory
          target:
            averageUtilization: 80
            type: Utilization
        type: Resource
      - pods:
          metric:
            name: tcpActiveConn
          target:
            averageValue: "100"
            type: AverageValue
        type: Pods
      - pods:
          metric:
            name: tcpTotalConn
          target:
            averageValue: "100"
            type: AverageValue
        type: Pods
      - external:
          metric:
            name: qps
          target:
            averageValue: "100"
            type: AverageValue
        type: External
      - external:
          metric:
            name: rt
          target:
            averageValue: 100k
            type: AverageValue
        type: External
      minReplicas: 1
      scaleTargetRef:
        apiVersion: apps/v1
        kind: Deployment
        name: test-app                         # Fixed format: ${application_name}
  2. From the directory where hpa.yaml is located, run:

    saectl apply -f hpa.yaml

List elastic policies

saectl get hpa -l sae.aliyun.com/app-name=<application-name> -n <namespace>
ParameterDescription
-l sae.aliyun.com/app-name=<application-name>Filter by application name. If omitted, returns all HPAs in scope.
-n <namespace>Namespace ID. If omitted, the default namespace is used.

The output lists the following fields:

FieldDescription
NAMEElastic policy name. Format: metric-${application_name}.
REFERENCEKINDAssociated resource type.
REFERENCENAMEName of the associated application.
MINPODSMinimum number of instances.
MAXPODSMaximum number of instances.
CURRENTREPLICASCurrent number of running instances.
DESIREDREPLICASTarget number of instances.
ENABLEDWhether the elastic policy is enabled.

View elastic policy details

You can view the details of an elastic policy using the get or describe command. The output contains the configuration items of the elastic policy.

Get structured output

saectl get hpa <hpa-name> -o {yaml | json} -n <namespace>
ParameterDescription
<hpa-name>Name of the HPA. Format: metric-${application_name}.
-oOutput format: yaml or json.
-n <namespace>Namespace ID. If omitted, the default namespace is used.

Describe an elastic policy

saectl describe hpa <hpa-name> -n <namespace>
ParameterDescription
<hpa-name>Name of the HPA. Format: metric-${application_name}.
-n <namespace>Namespace ID. If omitted, the default namespace is used.

Update an elastic policy

Two methods are available: edit the policy online with edit, or apply an updated YAML file with apply.

Edit online

  1. Open the policy configuration in your editor:

    saectl edit hpa <hpa-name> -n <namespace>
  2. Modify the configuration as needed, then save and close the file for the changes to take effect.

Apply from a YAML file

Modify the existing hpa.yaml file, then run:

saectl apply -f hpa.yaml

Delete an elastic policy

saectl delete hpa <hpa-name> -n <namespace>
ParameterDescription
<hpa-name>Name of the HPA. Format: metric-${application_name}.
-n <namespace>Namespace ID. If omitted, the default namespace is used.

K8s YAML configuration reference

SAE elastic policies use the Kubernetes HPA resource type (autoscaling/v2). The following table describes the supported configuration fields.

FieldDescriptionRequired for creationUpdatableConstraints
metadata.nameElastic policy name. Use the fixed format metric-${application_name}.YesNo
metadata.namespaceNamespace where the elastic policy resides.No
metadata.annotations: sae.aliyun.com/aliasNickname for the elastic policy.No
metadata.annotations: sae.aliyun.com/enabledWhether to enable the elastic policy.YesValid values: "true" (enabled), "false" (disabled)
metadata.uidElastic policy UID. Use the fixed format metric-${application_ID}.No
metadata.labelsLabel for the elastic policy. Use the fixed format sae.aliyun.com/app-name: ${application_name}.No
spec.behavior.scaleDown.policies[i]Scale-in step size configuration. Set value to configure the step size. periodSeconds (15) and type (Pods) are fixed by SAE and cannot be modified.OptionalperiodSeconds and type are fixed
spec.behavior.scaleUp.policies[i]Scale-out step size configuration. Set value to configure the step size. periodSeconds (15) and type (Pods) are fixed by SAE and cannot be modified.OptionalperiodSeconds and type are fixed
spec.maxReplicasMaximum number of instances.
spec.minReplicasMinimum number of instances.
spec.scaleTargetRefTarget application reference. Required for creation, not updatable.YesNoFixed format: apiVersion: apps/v1, kind: Deployment, name: <application_name>