metrics-server这里不详细介绍,可以参考metrics-server安装季
安装metrics-server
这里安装和之前的metrics-server安装季稍微有点不一样,之前集群安装没有使用https证书,后面去各种生成的证书和踩坑,这里是在安装的时候一开始就使用了https全证书,所有稍微有一点区别,这里只列出有区别的地方,其他的完全可以参考metrics-server安装季,这里https证书不需要重新生成;
配置文件也不需要添加,在v1.14安装的时候就已经吧配置文件添加进去了,所以这里配置文件也不需要增加
文件的修改
修改 metrics-server-deployment.yaml
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# cat metrics-server-deployment.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: metrics-server
namespace: kube-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: metrics-server
namespace: kube-system
labels:
k8s-app: metrics-server
spec:
selector:
matchLabels:
k8s-app: metrics-server
template:
metadata:
name: metrics-server
labels:
k8s-app: metrics-server
spec:
serviceAccountName: metrics-server
hostNetwork: true 这个还是需要增加
volumes:
# mount in tmp so we can safely use from-scratch images and/or read-only containers
- name: tmp-dir
emptyDir: {}
containers:
- name: metrics-server
image: mirrorgooglecontainers/metrics-server-amd64:v0.3.4
imagePullPolicy: Always
args: # 这里不一样
- --metric-resolution=30s
- --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP
volumeMounts:
- name: tmp-dir
mountPath: /tmp–metric-resolution=30s:从 kubelet 采集数据的周期;
–kubelet-preferred-address-types:优先使用 InternalIP 来访问 kubelet,这样可以避免节点名称没有 DNS 解析记录时,通过节点名称调用节点 kubelet API 失败的情况(未配置时默认的情况);
hostNetwork: true: 这个不增加的会提示:
1
Error from server (ServiceUnavailable): the server is currently unable to handle the request
修改 resource-reader.yaml
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# cat resource-reader.yaml
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system:metrics-server
rules:
- apiGroups:
- ""
resources:
- pods
- nodes
- nodes/stats
- namespaces
verbs:
- get
- list
- watch
- apiGroups: # 增加
- "extensions"
resources:
- deployments
verbs:
- get
- list
- update
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: system:metrics-server
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:metrics-server
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
执行创建
1 | # kubectl apply -f ./ |
查看运行情况
1 | # kubectl -n kube-system get pods -l k8s-app=metrics-server |
获取v1beta1.metrics.k8s.io并验证
1 | # kubectl get apiservice |
metrics-server 的命令行参数
1 | # kubectl exec --namespace kube-system -it metrics-server-94ff5d4cc-b97l5 -- /metrics-server --help |
注: 如果是使用metrics-server 源码安装的,metrics-server-deployment.yaml文件需要这样修改,其他修改不变
修改1
1
2
3
4
5
6
7
8
9
10
11- name: metrics-server
image: mirrorgooglecontainers/metrics-server-amd64:v0.3.6
args:
- --cert-dir=/tmp
- --secure-port=4443
- --metric-resolution=30s
- --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP
ports:
- name: main-port
containerPort: 4443
protocol: TCP修改2
除了上述修改,还可以用这种方式修改1
2
3
4
5
6command:
- /metrics-server
- --cert-dir=/tmp
- --kubelet-insecure-tls
- --secure-port=4443
- --kubelet-preferred-address-types=InternalIp,Hostname,InternalDNS,ExternalDNS,ExternalIP