Kubernetes的cronhpa怎么安装使用
这篇“Kubernetes的cronhpa怎么安装使用”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Kubernetes的cronhpa怎么安装使用”文章吧。
山丹ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!
使用方式
cronhpa
是基于 CRD 的方式开发的 controller,使用 cronhpa
的方式非常简单,整体的使用习惯也尽可能的和 HPA 保持一致。代码仓库地址
1. 安装 CRD
kubectl apply -f config/crds/autoscaling_v1beta1_cronhorizontalpodautoscaler.yaml
2. 安装 RBAC 授权
# create ClusterRole kubectl apply -f config/rbac/rbac_role.yaml # create ClusterRolebinding and ServiceAccount kubectl apply -f config/rbac/rbac_role_binding.yaml
3. 部署 kubernetes-cronhpa-controller
kubectl apply -f config/deploy/deploy.yaml
4. 验证 kubernetes-cronhpa-controller
安装状态
kubectl get deploy kubernetes-cronhpa-controller -n kube-system -o wide kubernetes-cronhpa-controller git:(master) kubectl get deploy kubernetes-cronhpa-controller -n kube-system NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE kubernetes-cronhpa-controller 1 1 1 1 49s
运行一个 cronhpa 的 demo
安装了 kubernetes-cronhpa-controller
后,我们可以通过一个简单的 demo 进行功能的验证。在部署前,我们先看下一个标准的 cronhpa 的定义。
apiVersion: autoscaling.alibabacloud.com/v1beta1 kind: CronHorizontalPodAutoscaler metadata: labels: controller-tools.k8s.io: "1.0" name: cronhpa-sample namespace: default spec: scaleTargetRef: apiVersion: apps/v1beta2 kind: Deployment name: nginx-deployment-basic jobs: - name: "scale-down" schedule: "30 */1 * * * *" targetSize: 1 - name: "scale-up" schedule: "0 */1 * * * *" targetSize: 3
其中 scaleTargetRef
字段负责描述伸缩的对象,jobs
中定义了扩展的 crontab
定时任务。在这个例子中,设定的是每分钟的第 0 秒扩容到 3 个 Pod,每分钟的第 30s 缩容到 1 个 Pod。如果执行正常,我们可以在 30s 内看到负载数目的两次变化。
1. 部署 demo 应用与 cronhpa 的配置
kubectl apply -f examples/deployment_cronhpa.yaml
2. 检查 demo 应用副本数目
kubectl get deploy nginx-deployment-basic kubernetes-cronhpa-controller git:(master) kubectl get deploy nginx-deployment-basic NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE nginx-deployment-basic 2 2 2 2 9s
3. 查看 cronhpa 的状态 ,确认 cronhpa 的 job 已提交
kubectl describe cronhpa cronhpa-sample Name: cronhpa-sample Namespace: default Labels: controller-tools.k8s.io=1.0 Annotations: kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"autoscaling.alibabacloud.com/v1beta1","kind":"CronHorizontalPodAutoscaler","metadata":{"annotations":{},"labels":{"controll... API Version: autoscaling.alibabacloud.com/v1beta1 Kind: CronHorizontalPodAutoscaler Metadata: Creation Timestamp: 2019-04-14T10:42:38Z Generation: 1 Resource Version: 4017247 Self Link: /apis/autoscaling.alibabacloud.com/v1beta1/namespaces/default/cronhorizontalpodautoscalers/cronhpa-sample UID: 05e41c95-5ea2-11e9-8ce6-00163e12e274 Spec: Jobs: Name: scale-down Schedule: 30 */1 * * * * Target Size: 1 Name: scale-up Schedule: 0 */1 * * * * Target Size: 3 Scale Target Ref: API Version: apps/v1beta2 Kind: Deployment Name: nginx-deployment-basic Status: Conditions: Job Id: 38e79271-9a42-4131-9acd-1f5bfab38802 Last Probe Time: 2019-04-14T10:43:02Z Message: Name: scale-down Schedule: 30 */1 * * * * State: Submitted Job Id: a7db95b6-396a-4753-91d5-23c2e73819ac Last Probe Time: 2019-04-14T10:43:02Z Message: Name: scale-up Schedule: 0 */1 * * * * State: Submitted Events:
4. 等待一段时间,查看 cronhpa 的运行状态
kubernetes-cronhpa-controller git:(master) kubectl describe cronhpa cronhpa-sample Name: cronhpa-sample Namespace: default Labels: controller-tools.k8s.io=1.0 Annotations: kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"autoscaling.alibabacloud.com/v1beta1","kind":"CronHorizontalPodAutoscaler","metadata":{"annotations":{},"labels":{"controll... API Version: autoscaling.alibabacloud.com/v1beta1 Kind: CronHorizontalPodAutoscaler Metadata: Creation Timestamp: 2019-04-15T06:41:44Z Generation: 1 Resource Version: 15673230 Self Link: /apis/autoscaling.alibabacloud.com/v1beta1/namespaces/default/cronhorizontalpodautoscalers/cronhpa-sample UID: 88ea51e0-5f49-11e9-bd0b-00163e30eb10 Spec: Jobs: Name: scale-down Schedule: 30 */1 * * * * Target Size: 1 Name: scale-up Schedule: 0 */1 * * * * Target Size: 3 Scale Target Ref: API Version: apps/v1beta2 Kind: Deployment Name: nginx-deployment-basic Status: Conditions: Job Id: 84818af0-3293-43e8-8ba6-6fd3ad2c35a4 Last Probe Time: 2019-04-15T06:42:30Z Message: cron hpa job scale-down executed successfully Name: scale-down Schedule: 30 */1 * * * * State: Succeed Job Id: f8579f11-b129-4e72-b35f-c0bdd32583b3 Last Probe Time: 2019-04-15T06:42:20Z Message: Name: scale-up Schedule: 0 */1 * * * * State: Submitted Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Succeed 5s cron-horizontal-pod-autoscaler cron hpa job scale-down executed successfully
此时可以在 event 中发现负载的定时伸缩已经生效。
以上就是关于“Kubernetes的cronhpa怎么安装使用”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注创新互联行业资讯频道。
网站名称:Kubernetes的cronhpa怎么安装使用
转载来于:http://cdiso.cn/article/jpgejs.html