k8s HPA自动收缩
Posted zhangb8042
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s HPA自动收缩相关的知识,希望对你有一定的参考价值。
HPA自动收缩 autoscale 自动调整一个 Deployment, ReplicaSet, 或者 ReplicationController 的副本数量 #创建一个replicaset测试 [[email protected] ~]# cat my-replicaset.yaml apiVersion: apps/v1 kind: ReplicaSet metadata: name: myreplicaset namespace: default spec: replicas: 2 selector: matchLabels: test_node: k8s-node1 template: metadata: name: my-replicaset-pod labels: test_node: k8s-node1 spec: containers: - name: my-rep image: nginx ports: - name: http containerPort: 80 resources: requests: cpu: "100m" memory: "64Mi" limits: memory: "64Mi" cpu: "100m" #导入 kubectl apply -f my-replicaset.yaml #查看 [[email protected] ~]# kubectl get pod NAME READY STATUS RESTARTS AGE myreplicaset-8prkv 1/1 Running 0 55s myreplicaset-8sbgs 1/1 Running 0 55s #设置自动伸缩 #设置myreplicaset 最少1个,最多10个,cpu资源最多使用40% kubectl autoscale replicaset myreplicaset --min=1 --max=10 --cpu-percent=40 #查看hpa [[email protected] ~]# kubectl get hpa NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE myreplicaset ReplicaSet/myreplicaset <unknown>/40% 1 10 0 29s
以上是关于k8s HPA自动收缩的主要内容,如果未能解决你的问题,请参考以下文章