您好,登錄后才能下訂單哦!
這篇“Kubernetes的cronhpa怎么安裝使用”文章的知識點大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“Kubernetes的cronhpa怎么安裝使用”文章吧。
cronhpa
是基于 CRD 的方式開發(fā)的 controller,使用 cronhpa
的方式非常簡單,整體的使用習慣也盡可能的和 HPA 保持一致。代碼倉庫地址
kubectl apply -f config/crds/autoscaling_v1beta1_cronhorizontalpodautoscaler.yaml
# create ClusterRole kubectl apply -f config/rbac/rbac_role.yaml # create ClusterRolebinding and ServiceAccount kubectl apply -f config/rbac/rbac_role_binding.yaml
kubernetes-cronhpa-controller
kubectl apply -f config/deploy/deploy.yaml
kubernetes-cronhpa-controller
安裝狀態(tài)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
安裝了 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。如果執(zhí)行正常,我們可以在 30s 內(nèi)看到負載數(shù)目的兩次變化。
kubectl apply -f examples/deployment_cronhpa.yaml
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
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: <none>
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 中發(fā)現(xiàn)負載的定時伸縮已經(jīng)生效。
以上就是關(guān)于“Kubernetes的cronhpa怎么安裝使用”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關(guān)的知識內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。