AWS运维部署实践--EKS集群结合metrics-server配置HPA的功能
文章发布较早,内容可能过时,阅读注意甄别。
hpa 对于实际生产业务中,已经是一个常态化的基础能力,因此这是一个绕不过去的话题,EKS 原生是没有组件直接应用的,因此需要借助于 metrics-server
来进行配置支持。
安装metrics-server
组件:
$ kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/high-availability-1.21+.yaml
1
然后部署一个测试 demo:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hpa-demo-deployment
labels:
app: hpa-nginx
spec:
replicas: 1
selector:
matchLabels:
app: hpa-nginx
template:
metadata:
labels:
app: hpa-nginx
spec:
containers:
- name: hpa-nginx
image: stacksimplify/kubenginx:1.0.0
ports:
- containerPort: 80
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "500Mi"
cpu: "200m"
---
apiVersion: v1
kind: Service
metadata:
name: hpa-demo-service-nginx
labels:
app: hpa-nginx
spec:
type: NodePort
selector:
app: hpa-nginx
ports:
- port: 80
targetPort: 80
nodePort: 30123
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: hpa-demo-deployment
namespace: default
spec:
maxReplicas: 3
metrics:
- resource:
name: cpu
target:
averageUtilization: 70
type: Utilization
type: Resource
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: hpa-demo-deployment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
然后下载一个 hey 命令,进行压测:
参考: https://www.cnblogs.com/dudu/p/12217354.html
./hey -c 100 -z 5m http://10.200.0.116:30123
1
然后观察容器是否会根据负载的高低进行动态扩缩容。
上次更新: 2024/11/19, 23:11:42