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:
The
saectltool installed, with an AccessKey ID, AccessKey secret, and application deployment region configured. For setup instructions, see Install and configure the saectl tool
Manage elastic policies
Create an elastic policy
Create a file named
hpa.yamlwith 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}From the directory where
hpa.yamlis located, run:saectl apply -f hpa.yaml
List elastic policies
saectl get hpa -l sae.aliyun.com/app-name=<application-name> -n <namespace>| Parameter | Description |
|---|---|
-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:
| Field | Description |
|---|---|
NAME | Elastic policy name. Format: metric-${application_name}. |
REFERENCEKIND | Associated resource type. |
REFERENCENAME | Name of the associated application. |
MINPODS | Minimum number of instances. |
MAXPODS | Maximum number of instances. |
CURRENTREPLICAS | Current number of running instances. |
DESIREDREPLICAS | Target number of instances. |
ENABLED | Whether 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>| Parameter | Description |
|---|---|
<hpa-name> | Name of the HPA. Format: metric-${application_name}. |
-o | Output 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>| Parameter | Description |
|---|---|
<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
Open the policy configuration in your editor:
saectl edit hpa <hpa-name> -n <namespace>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.yamlDelete an elastic policy
saectl delete hpa <hpa-name> -n <namespace>| Parameter | Description |
|---|---|
<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.
| Field | Description | Required for creation | Updatable | Constraints |
|---|---|---|---|---|
metadata.name | Elastic policy name. Use the fixed format metric-${application_name}. | Yes | No | — |
metadata.namespace | Namespace where the elastic policy resides. | — | No | — |
metadata.annotations: sae.aliyun.com/alias | Nickname for the elastic policy. | — | No | — |
metadata.annotations: sae.aliyun.com/enabled | Whether to enable the elastic policy. | — | Yes | Valid values: "true" (enabled), "false" (disabled) |
metadata.uid | Elastic policy UID. Use the fixed format metric-${application_ID}. | — | No | — |
metadata.labels | Label 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. | Optional | — | periodSeconds 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. | Optional | — | periodSeconds and type are fixed |
spec.maxReplicas | Maximum number of instances. | — | — | — |
spec.minReplicas | Minimum number of instances. | — | — | — |
spec.scaleTargetRef | Target application reference. Required for creation, not updatable. | Yes | No | Fixed format: apiVersion: apps/v1, kind: Deployment, name: <application_name> |