kubernetes: hpa实践
环境信息本文的实验环境是k3sENV:#[root@k8s-1 ~]# kubectl get nodes -o wide确保metrics-server运行正常hpa配置apiVersion: autoscaling/v2beta1kind: HorizontalPodAutoscalermetadata:name: pod-hpaspec:scaleT...
·
环境信息
本文的实验环境是k3s
ENV:
#[root@k8s-1 ~]# kubectl get nodes -o wide
确保metrics-server运行正常
hpa配置
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: pod-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: hpa
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 85
- type: Resource
resource:
name: memory
targetAverageUtilization: 85
scaleTargetRef 中的三个参数 要注意:
apiVersion,kind,name 均要和pod的描述保持一致
#2.deployment configuration list:
运行pod
kubectl run hpa --image=ikubernetes/myapp:v1 --replicas=1 --requests='cpu=50m,memory=128Mi' --labels=app=myapp'' --expose --port=80
pod 一定要指定cpu,memory ,这样 hpa 中定义的cpu memory两个参数才能获取到信息
结果:
[root@k8s-1 ~]# kubectl get pod,deploy,svc -o wide
压力测试:
安装httpd-tools
yum -y install httpd-tools
压力测试
[root@k8s-1 ~]# ab -c 1000 -n 500000 http://10.43.107.105/index.html
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 10.43.107.105 (be patient)
Completed 50000 requests
Completed 100000 requests
Completed 150000 requests
Completed 200000 requests
Completed 250000 requests
Completed 300000 requests
Completed 350000 requests
Completed 400000 requests
Completed 450000 requests
Completed 500000 requests
Finished 500000 requests
Server Software: nginx/1.12.2
Server Hostname: 10.43.107.105
Server Port: 80
Document Path: /index.html
Document Length: 65 bytes
Concurrency Level: 1000
Time taken for tests: 67.163 seconds
Complete requests: 500000
Failed requests: 0
Write errors: 0
Total transferred: 148000000 bytes
HTML transferred: 32500000 bytes
Requests per second: 7444.54 [#/sec] (mean)
Time per request: 134.327 [ms] (mean)
Time per request: 0.134 [ms] (mean, across all concurrent requests)
Transfer rate: 2151.94 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 105 493.3 5 15082
Processing: 3 29 35.1 13 1626
Waiting: 0 21 28.4 9 1619
Total: 9 134 496.3 18 15170
Percentage of the requests served within a certain time (ms)
50% 18
66% 23
75% 46
80% 128
90% 163
95% 1020
98% 1042
99% 3021
100% 15170 (longest request)
4.测试结果
[root@k8s-1 ~]# kubectl get pods -o wide -w
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-deployment-59c9f8dff-pk5nr 1/1 Terminating 0 87d 10.42.0.13 myserver <none> <none>
nginx-deployment-697cbb4d8b-lpj9w 1/1 Running 0 125m 10.42.0.15 myserver <none> <none>
hpa-5d8bcd9f94-6pvrl 1/1 Running 0 119m 10.42.0.16 myserver <none> <none>
hpa-5d8bcd9f94-ljbzj 1/1 Running 0 62s 10.42.0.26 myserver <none> <none>
hpa-5d8bcd9f94-4dhfs 1/1 Running 0 62s 10.42.0.27 myserver <none> <none>
hpa-5d8bcd9f94-q4gfc 1/1 Running 0 62s 10.42.0.25 myserver <none> <none>
hpa-5d8bcd9f94-b6rp9 1/1 Running 0 47s 10.42.0.31 myserver <none> <none>
hpa-5d8bcd9f94-bcbb8 1/1 Running 0 47s 10.42.0.29 myserver <none> <none>
hpa-5d8bcd9f94-2gws5 1/1 Running 0 47s 10.42.0.30 myserver <none> <none>
hpa-5d8bcd9f94-crpdc 1/1 Running 0 47s 10.42.0.28 myserver <none> <none>
hpa-5d8bcd9f94-zrjc8 1/1 Running 0 32s 10.42.0.32 myserver <none> <none>
出现了9个扩展的pod
查看hpa的状态
kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
pod-hpa Deployment/hpa 1%/85%, 0%/85% 1 10 9 119m
[root@myserver ~]# kubectl describe hpa/pod-hpa
Name: pod-hpa
Namespace: default
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"autoscaling/v2beta1","kind":"HorizontalPodAutoscaler","metadata":{"annotations":{},"name":"pod-hpa","namespace":"default"},...
CreationTimestamp: Tue, 10 Mar 2020 11:28:39 +0800
Reference: Deployment/hpa
Metrics: ( current / target )
resource memory on pods (as a percentage of request): 1% (2369763555m) / 85%
resource cpu on pods (as a percentage of request): 0% (0) / 85%
Min replicas: 1
Max replicas: 10
Deployment pods: 9 current / 9 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True ScaleDownStabilized recent recommendations were higher than current one, applying the highest recent recommendation
ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from memory resource utilization (percentage of request)
ScalingLimited False DesiredWithinRange the desired count is within the acceptable range
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulRescale 3m41s (x2 over 117m) horizontal-pod-autoscaler New size: 4; reason: cpu resource utilization (percentage of request) above target
Normal SuccessfulRescale 3m26s (x2 over 117m) horizontal-pod-autoscaler New size: 8; reason: cpu resource utilization (percentage of request) above target
Normal SuccessfulRescale 3m11s (x2 over 117m) horizontal-pod-autoscaler New size: 9; reason:
更多推荐
已为社区贡献18条内容
所有评论(0)