CronHPA是针对定时水平扩容的一个kubernetes的组件,类似linux的crontab的功能。CronHPA会依据HPA的特点和自身的特点,在使用过程中可以单独使用也可以同时使用,下面先看看cronHPA的安装方法吧:
下载cronHPA
[wolf@wulaoer.org🔥🔥🔥🔥 ~]# git clone https://github.com/AliyunContainerService/kubernetes-cronhpa-controller.git Cloning into 'kubernetes-cronhpa-controller'... remote: Enumerating objects: 34191, done. remote: Counting objects: 100% (442/442), done. remote: Compressing objects: 100% (350/350), done. Receiving objects: 39% (13335/34191), 23.14 MiB | 1007.00 KiB/Receiving objects: 39% (13645/34191), 23.14 MiB | 1007.00 KiB/Receiving objects: 40% (13677/34191), 23.14 MiB | 1007.00 KiB/Receiving objects: 41% (14019/34191), 23.61 MiB | 1008.00 KiB/Receiving objects: 42% (14361/34191), 23.61 MiB | 1008.00 KiB/Receiving objects: 43% (14703/34191), 24.05 MiB | 986.00 Kiremote: Total 34191 (delta 137), reused 279 (delta 78), pack-reused 33749 Receiving objects: 100% (34191/34191), 54.10 MiB | 1.04 MiB/s, done. Resolving deltas: 100% (13799/13799), done.
可能会因为翻墙的问题,不过没关系,可以先下载到本地,然后在传到节点上,在进行解压,后面就都一样了。
安装 RBAC 设置
[wolf@wulaoer.org🔥🔥🔥🔥 hpa]# cd kubernetes-cronhpa-controller-master/ [wolf@wulaoer.org🔥🔥🔥🔥 kubernetes-cronhpa-controller-master]# kubectl apply -f config/crds/autoscaling_v1beta1_cronhorizontalpodautoscaler.yaml Warning: apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition customresourcedefinition.apiextensions.k8s.io/cronhorizontalpodautoscalers.autoscaling.alibabacloud.com created [wolf@wulaoer.org🔥🔥🔥🔥 kubernetes-cronhpa-controller-master]# kubectl apply -f config/rbac/rbac_role.yaml clusterrole.rbac.authorization.k8s.io/kubernetes-cronhpa-controller-role created [wolf@wulaoer.org🔥🔥🔥🔥 kubernetes-cronhpa-controller-master]# kubectl apply -f config/rbac/rbac_role_binding.yaml serviceaccount/kubernetes-cronhpa-controller created clusterrolebinding.rbac.authorization.k8s.io/kubernetes-cronhpa-controller-rolebinding created [wolf@wulaoer.org🔥🔥🔥🔥 kubernetes-cronhpa-controller-master]# kubectl api-resources |grep cronhpa cronhorizontalpodautoscalers cronhpa autoscaling.alibabacloud.com/v1beta1 true CronHorizontalPodAutoscaler
部署kubernetes-cronhpa-controller
[wolf@wulaoer.org🔥🔥🔥🔥 kubernetes-cronhpa-controller-master]# kubectl apply -f config/deploy/deploy.yaml deployment.apps/kubernetes-cronhpa-controller created [wolf@wulaoer.org🔥🔥🔥🔥 kubernetes-cronhpa-controller-master]# kubectl get deploy kubernetes-cronhpa-controller -n kube-system NAME READY UP-TO-DATE AVAILABLE AGE kubernetes-cronhpa-controller 1/1 1 1 26s
验证kubernetes-cronhpa-controller,并根据文件中的例子说明。
[wolf@wulaoer.org🔥🔥🔥🔥 kubernetes-cronhpa-controller-master]# kubectl apply -f examples/deployment_cronhpa.yaml deployment.apps/nginx-deployment-basic created cronhorizontalpodautoscaler.autoscaling.alibabacloud.com/cronhpa-sample created [wolf@wulaoer.org🔥🔥🔥🔥 kubernetes-cronhpa-controller-master]# cat examples/deployment_cronhpa.yaml --- apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1 kind: Deployment metadata: name: nginx-deployment-basic labels: app: nginx spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 # replace it with your exactly <image_name:tags> ports: - containerPort: 80 --- apiVersion: autoscaling.alibabacloud.com/v1beta1 kind: CronHorizontalPodAutoscaler metadata: labels: controller-tools.k8s.io: "1.0" name: cronhpa-sample spec: scaleTargetRef: apiVersion: apps/v1beta2 kind: Deployment name: nginx-deployment-basic jobs: - name: "scale-down" schedule: "30 */1 * * * *" targetSize: 1 - name: "scale-up" schedule: "01 */1 * * * *" targetSize: 3 [wolf@wulaoer.org🔥🔥🔥🔥 kubernetes-cronhpa-controller-master]# kubectl get deploy nginx-deployment-basic NAME READY UP-TO-DATE AVAILABLE AGE nginx-deployment-basic 0/2 2 0 21s [wolf@wulaoer.org🔥🔥🔥🔥 kubernetes-cronhpa-controller-master]# kubectl get deploy nginx-deployment-basic NAME READY UP-TO-DATE AVAILABLE AGE nginx-deployment-basic 0/3 3 0 25s [wolf@wulaoer.org🔥🔥🔥🔥 kubernetes-cronhpa-controller-master]# kubectl get deploy nginx-deployment-basic NAME READY UP-TO-DATE AVAILABLE AGE nginx-deployment-basic 1/1 1 1 57s
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏