HorizontalPodCronscaler (HPC) is an add-on to modify the number of replicas of K8s workload. Used in conjunction with HPC CRD resources, it can support scheduled actions in seconds.
Deploying HPC Add-on in a cluster will deploy the following Kubernetes objects in the cluster:
Kubernetes Object | Type | Required Resources | Namespaces |
---|---|---|---|
horizontalpodcronscalers.autoscaling.cloud.tencent.com | CustomResourceDefinition | - | - |
hpc-leader-election-role | Role | - | kube-system |
hpc-leader-election-rolebinding | RoleBinding | - | kube-system |
hpc-manager-role | ClusterRole | - | - |
hpc-manager-rolebinding | ClusterRoleBinding | - | - |
cronhpa-controller-manager-metrics-service | Service | - | kube-system |
hpc-manager | ServiceAccount | - | kube-system |
tke-hpc-controller | Deployment | 100mCPU, 100Mi/pod | kube-system |
Note:If you create a cluster of version 1.12.4 or later, you can use the cluster directly without any parameter changes.
--feature-gates=CustomResourceSubresources=true
./etc/localtime
file exists in the node.When you create an HPC resource, please make sure that the workload (K8s resource) to be controlled exists in the cluster.
The example is as follows:
apiVersion: autoscaling.cloud.tencent.com/v1
kind: HorizontalPodCronscaler
metadata:
name: hpc-deployment
namespace: default
spec:
scaleTarget:
apiVersion: apps/v1
kind: Deployment
name: nginx-deployment
namespace: default
crons:
- name: "scale-down"
excludeDates:
- "* * * 15 11 *"
- "* * * * * 5"
schedule: "30 */1 * * * *"
targetSize: 1
- name: "scale-up"
excludeDates:
- "* * * 15 11 *"
- "* * * * * 5"
schedule: "0 */1 * * * *"
targetSize: 3
The example is as follows:
apiVersion: autoscaling.cloud.tencent.com/v1
kind: HorizontalPodCronscaler
metadata:
name: hpc-statefulset
namespace: default
spec:
scaleTarget:
apiVersion: apps/v1
kind: Statefulset
name: nginx-statefulset
namespace: default
crons:
- name: "scale-down"
excludeDates:
- "* * * 15 11 *"
schedule: "0 */2 * * * *"
targetSize: 1
- name: "scale-up"
excludeDates:
- "* * * 15 11 *"
schedule: "30 */2 * * * *"
targetSize: 4
The example is as follows:
apiVersion: autoscaling.cloud.tencent.com/v1
kind: HorizontalPodCronscaler
metadata:
labels:
controller-tools.k8s.io: "1.0"
name: hpc-hpa
spec:
scaleTarget:
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
name: nginx-hpa
namespace: default
crons:
- name: "scale-up"
schedule: "30 */1 * * * *"
minSize: 2
maxSize: 6
- name: "scale-down"
schedule: "0 */1 * * * *"
minSize: 1
maxSize: 5
Field Name | Required | Value Range | Allowed Special Characters |
---|---|---|---|
Seconds | Yes | 0 - 59 | * / , - |
Minutes | Yes | 0 - 59 | * / , - |
Hours | Yes | 0 - 23 | * / , - |
Day of month | Yes | 1 - 31 | * / , - ? |
Month | Yes | 1 - 12 or JAN - DEC | * / , - |
Day of week | Yes | 0 - 6 or SUN - SAT | * / , - ? |
Was this page helpful?