容器服务 HPC 说明

HPC(HorizontalPodCronscaler)是一种可以对 Kubernetes workload 副本数进行定时修改的自研组件,配合 HPC CRD 使用,最小支持秒级的定时任务。

相关产品
容器服务 产品页,含版本规格、价格与购买入口。

三、组件功能

·支持设置“实例范围”(关联对象为 HPA)或“目标实例数量”(关联对象为 deployment 和 statefulset)。

·支持开关“例外时间”。例外时间的最小配置粒度是日期,支持设置多条。

·支持设置定时任务是否只执行一次。

四、部署在集群内的 Kubernetes 对象

在集群内部署 HPC , 将在集群内部署以下 Kubernetes 对象:

Kubernetes 对象名称 类型 默认占用资源 所属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/pod、100Mi/pod kube-system

六、环境要求

注意:说明:

注意:你在创建集群时选择1.12.4以上版本集群,无需修改任何参数,开箱可用。

·仅支持1.12版本以上的 Kubernetes。

·需设置 kube-apiserver 的启动参数:–feature-gates=CustomResourceSubresources=true

七、节点要求

·HPC 组件默认挂载主机的时区将作为定时任务的参考时间,因此要求节点存在 /etc/localtime 文件。

·HPC 默认安装2个 HPC Pod 在不同节点,因此节点数推荐为2个及以上。

八、被控资源要求

在创建 HPC 资源时,被控制的 workload(Kubernetes 资源)需要存在于集群中。

十、权限说明

该组件权限是当前功能实现的最小权限依赖。

十一、权限场景

功能 涉及对象 涉及操作权限
监听 horizontalpodcronscalers 的变动 horizontalpodcronscalers create/delete/get/list/patch/watch
需要修改 deployments/statefulsets 的 replicas deployments/statefulsets get/list/patch/watch
修改 horizontalpodautoscalers 的 minReplicas/maxReplicas horizontalpodautoscalers get/list/patch/watch
同步 HPC 定时任务执行的 events events create/patch

十二、权限定义

apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: creationTimestamp: null name: hpc-manager-rolerules:- apiGroups: – "" resources: – events verbs: – create – patch- apiGroups: – apps resources: – deployments verbs: – get – list – patch – watch- apiGroups: – apps resources: – statefulsets verbs: – get – list – patch – watch- apiGroups: – autoscaling resources: – horizontalpodautoscalers verbs: – get – list – patch – watch- apiGroups: – autoscaling.cloud.tencent.com resources: – horizontalpodcronscalers verbs: – create – delete – get – list – patch – update – watch- apiGroups: – autoscaling.cloud.tencent.com resources: – horizontalpodcronscalers/status verbs: – get – patch – update- apiGroups: – apiextensions.k8s.io resources: – customresourcedefinitions resourceNames: – horizontalpodcronscalers.autoscaling.cloud.tencent.com verbs: – get – list – delete – watch

十四、安装 HPC

1. 登录 容器服务控制台,在左侧导航栏中选择集群。

2. 在集群列表中,单击目标集群 ID,进入集群详情页。

3. 选择左侧菜单栏中的组件管理,在组件管理页面单击新建。

4. 在新建组件管理页面中勾选 HPC。

5. 单击完成即可创建组件。

十五、HPC 支持 Openkruise 的高级 workload 类型

HPC 组件自v1.0.8版本之后,支持 OpenKruise 的高级 workload 类型,操作步骤如下:

1. 在集群中安装 OpenKruise 组件,请参考产品文档 OpenKruise 安装指南。

2. 创建关联 OpenKruise 高级工作负载类型的 HPC。

2.1 在 集群 页面,选择集群 ID,进入集群的基本信息页面。

2.2 选择左侧导航中的自动伸缩,在 HorizontalPodCronscaler 页面,单击编辑 YAML。

关联 CloneSet:

apiVersion: autoscaling.cloud.tencent.com/v1kind: HorizontalPodCronscalermetadata: name: hpc-cloneset namespace: default spec: scaleTarget: apiVersion: apps.kruise.io/v1alpha1 kind: CloneSet 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

关联 Advanced StatefulSet:

apiVersion: autoscaling.cloud.tencent.com/v1kind: HorizontalPodCronscalermetadata: name: hpc-ad namespace: default spec: scaleTarget: apiVersion: apps.kruise.io/v1beta1 kind: Statefulset 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

十七、创建关联 Deployment 的定时任务资源

示例如下:

apiVersion: autoscaling.cloud.tencent.com/v1kind: HorizontalPodCronscalermetadata: 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

十八、创建关联 StatefulSet 的定时任务资源

示例如下:

apiVersion: autoscaling.cloud.tencent.com/v1kind: HorizontalPodCronscalermetadata: name: hpc-statefulset namespace: defaultspec: 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

十九、创建关联 HPA 的定时任务资源

示例如下:

apiVersion: autoscaling.cloud.tencent.com/v1kind: HorizontalPodCronscalermetadata: labels: controller-tools.k8s.io: "1.0" name: hpc-hpaspec: 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

20、定时时间设置参考

字段名称 是否必选 允许值范围 允许的特殊字符
Seconds 是 0 – 59 * / , –
Minutes 是 0 – 59 * / , –
Hours 是 0 – 23 * / , –
Day of month 是 1 – 31 * / , – ?
Month 是 1 – 12 或 JAN – DEC * / , –
Day of week 是 0 – 6 或 SUN – SAT * / , – ?

注意:当定时时间设置同时包含星期几和月份日期时,若时间匹配其中任一设置,命令都会执行。例如,设置 "* 30 4 1,15 * 5" 将导致命令在每个月的1日和15日的凌晨4:30以及每个星期五运行。更多定时时间设置格式可参考 crontab 规范。

21、HPC 任务的挂起

从 v1.0.9 版本开始,HPC 组件新增了任务挂起功能。通过在 hpc yaml 文件中配置 suspend 字段,可以让指定的 job 临时挂起。挂起后,该任务将跳过后续的执行周期。具体配置如下:

赞 (0)
上一篇 4天前
下一篇 4天前