简单说明
pencil.file.lynchj.com
Metrics Server
是用来监控 k8s 集群资源使用情况的组件,是用来替换掉之前的Heapster
的。从 k8s 1.8 开始,资源的使用情况就可以通过Metrics API
的形式获取到,Metrics Server
组件就是其具体的实现。
Heapster
在 k8s 1.11 时就已经不添加新功能了、在 1.12 时已经从 k8s 安装脚本中删除掉了、在 1.13 中已经彻底切除连错误修正都不会更新了。详情可以查看说明。
安装
下载 yaml 文件
wget http://pencil.file.lynchj.com/blog/auth-delegator.yaml
wget http://pencil.file.lynchj.com/blog/metrics-server-service.yaml
wget http://pencil.file.lynchj.com/blog/auth-reader.yaml
wget http://pencil.file.lynchj.com/blog/metrics-apiservice.yaml
wget http://pencil.file.lynchj.com/blog/metrics-server-deployment.yaml
wget http://pencil.file.lynchj.com/blog/aggregated-metrics-reader.yaml
wget http://pencil.file.lynchj.com/blog/resource-reader.yaml
微微修改
✨在 apply 之前还需要做一些操作
- 修改
metrics-server-deployment.yaml
文件修改镜像默认拉去策略为IfNotPresent
:
$ vim metrics-server-deployment.yaml
containers:
- name: metrics-server
image: k8s.gcr.io/metrics-server-amd64:v0.3.2
# imagePullPolicy: Always
imagePullPolicy: IfNotPresent
volumeMounts:
- name: tmp-dir
mountPath: /tmp
-
由于拉取的镜像是
k8s.gcr.io/metrics-server-amd64:v0.3.2
,没有科学上网是拉取不下来的,可以下载之后使用docker load
导入。 -
修改使用 IP 连接并且不验证证书:
$ vim metrics-server-deployment.yaml
containers:
- name: metrics-server
image: k8s.gcr.io/metrics-server-amd64:v0.3.2
# imagePullPolicy: Always
imagePullPolicy: IfNotPresent
command:
- /metrics-server
- --kubelet-insecure-tls
- --kubelet-preferred-address-types=InternalIP
volumeMounts:
- name: tmp-dir
mountPath: /tmp
部署
$ kubectl apply -f ./
查看监控数据
$ kubectl top nodes
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
k8s-master 127m 6% 678Mi 17%
k8s-node-1 53m 2% 594Mi 31%
k8s-node-2 36m 1% 570Mi 30%
$ kubectl top pod --all-namespaces
NAMESPACE NAME CPU(cores) MEMORY(bytes)
default springbootdemo-56d8697f47-2zznb 5m 123Mi
default springbootdemo-56d8697f47-46fgj 6m 144Mi
default springbootdemo-56d8697f47-7v5tz 5m 141Mi
default springbootdemo-56d8697f47-qmw8j 4m 116Mi
kube-system coredns-fb8b8dccf-jr2sp 3m 12Mi
kube-system coredns-fb8b8dccf-pbpmv 3m 12Mi
kube-system etcd-k8s-master 14m 60Mi
kube-system kube-apiserver-k8s-master 26m 142Mi
kube-system kube-controller-manager-k8s-master 14m 44Mi
kube-system kube-flannel-ds-amd64-62pwl 2m 11Mi
kube-system kube-flannel-ds-amd64-hjfjb 2m 14Mi
kube-system kube-flannel-ds-amd64-td24r 2m 13Mi
kube-system kube-proxy-9cggp 5m 17Mi
kube-system kube-proxy-k8lw2 1m 19Mi
kube-system kube-proxy-xl8gj 1m 17Mi
kube-system kube-scheduler-k8s-master 2m 13Mi
kube-system kubernetes-dashboard-5f7b999d65-h96kl 1m 14Mi
kube-system metrics-server-866db9bd9d-rv7vg 1m 12Mi
文章评论