首页 > 应用开发 > IT综合 > Kubernetes Pod水平自动伸缩(HPA)

apiVersion: apps/v1 kind: Deployment metadata: labels: app: nginx name: nginx namespace: hpa spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - image: nginx name: nginx resources: requests: cpu: 200m memory: 100Mi --- apiVersion: v1 kind: Service metadata: name: nginx namespace: hpa spec: type: NodePort ports: - port: 80 targetPort: 80 selector: app: nginx
[root@k8s-node001 HPA]# kubectl get po -n hpa NAME READY STATUS RESTARTS AGE nginx-5c87768685-48b4v 1/1 Running 0 8m38s nginx-5c87768685-kfpkq 1/1 Running 0 8m38s
apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: name: nginx namespace: hpa spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: nginx minReplicas: 1 maxReplicas: 10 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 50
[root@k8s-node001 HPA]# kubectl get hpa -n hpa NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE nginx Deployment/nginx 0%/50% 1 10 2 50s
[root@k8s-node001 ~]# ab -c 1000 -n 100000000 http://192.168.100.185:30792/ This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.100.185 (be patient)
[root@k8s-node001 HPA]# kubectl get hpa -n hpa NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE nginx Deployment/nginx 303%/50% 1 10 7 12m [root@k8s-node001 HPA]# kubectl get po -n hpa NAME READY STATUS RESTARTS AGE pod/nginx-5c87768685-6b4sl 1/1 Running 0 85s pod/nginx-5c87768685-99mjb 1/1 Running 0 69s pod/nginx-5c87768685-cls7r 1/1 Running 0 85s pod/nginx-5c87768685-hhdr7 1/1 Running 0 69s pod/nginx-5c87768685-jj744 1/1 Running 0 85s pod/nginx-5c87768685-kfpkq 1/1 Running 0 27m pod/nginx-5c87768685-xb94x 1/1 Running 0 69s
[root@k8s-node001 ~]# kubectl get hpa -n hpa NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE nginx Deployment/nginx 20%/50% 1 10 7 16m 。。。N分钟后。。。 [root@k8s-node001 ~]# kubectl get hpa -n hpa NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE nginx Deployment/nginx 0%/50% 1 10 7 18m 。。。再过N分钟后。。。 [root@k8s-node001 ~]# kubectl get po -n hpa NAME READY STATUS RESTARTS AGE nginx-5c87768685-jj744 1/1 Running 0 11m
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69984138/viewspace-2732084/ ,如需转载,请注明出处,否则将追究法律责任。