一看必会系列:k8s核心指标API Metrics-Server部署指南

来源:本站原创 Docker 超过2,157 views围观 0条评论

Kubernetes1.13安装metrics-server及填坑

下载

https://github.com/kubernetes-incubator/metrics-server

wget https://codeload.github.com/kubernetes-incubator/metrics-server/zip/master

unzip master

进入目录

/opt/k8s/metrics-server/metrics-server-master/deploy/1.8+

替换镜地址

metrics-server-deployment.yaml: image: k8s.gcr.io/metrics-server-amd64:v0.3.1

好像没用,自己找个可用源吧

[root@k8s-master 1.8+]# grep gcr *

metrics-server-deployment.yaml: image: k8s.gcr.io/metrics-server-amd64:v0.3.1

[root@k8s-master 1.8+]# vim metrics-server-deployment.yaml

[root@k8s-master 1.8+]# grep amd64 *

metrics-server-deployment.yaml: image: registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server-amd64:v0.3.1

[root@k8s-master 1.8+]#

381 kubectl apply -f ./

382 kubectl get pods,svc -n kube-system -o wide

演示

[root@k8s-master 1.8+]# kubectl api-versions |grep me

metrics.k8s.io/v1beta1

[root@k8s-master 1.8+]#

[root@k8s-master 1.8+]# kubectl top nodes

NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%

k8s-master 178m 4% 1811Mi 23%

k8s-node1 38m 0% 749Mi 9%

k8s-node2 30m 0% 594Mi 7%

[root@k8s-master 1.8+]# kubectl top pods –all-namespaces

NAMESPACE NAME CPU(cores) MEMORY(bytes)

default nginx-5c7588df-dwbqx 0m 2Mi

kube-system coredns-78d4cf999f-84gkh 3m 14Mi

kube-system coredns-78d4cf999f-dhhh6 3m 14Mi

kube-system etcd-k8s-master 18m 314Mi

kube-system kube-apiserver-k8s-master 29m 484Mi

kube-system kube-controller-manager-k8s-master 37m 68Mi

kube-system kube-flannel-ds-amd64-8kf24 2m 17Mi

kube-system kube-flannel-ds-amd64-hgb9x 2m 15Mi

kube-system kube-flannel-ds-amd64-lmjh8 3m 17Mi

kube-system kube-proxy-564j5 2m 17Mi

kube-system kube-proxy-m4zs4 3m 17Mi

kube-system kube-proxy-n7z76 2m 17Mi

kube-system kube-scheduler-k8s-master 12m 20Mi

kube-system kubernetes-dashboard-76479d66bb-smj7l 1m 30Mi

kube-system metrics-server-6c8b76677-fx5mr 1m 13Mi

2.2正式部署

可以看到这个目录里面都是yaml文件,包含了所有需要配置的yaml文件,我们直接用命令一键部署

Kubectl apply –f /.

部署完发现报错,具体报错是因为metrics-server-depoyment里面的image

k8s.gcr.io/metrics-server-amd64:v0.3.1 的拉取策略是always,由于我的环境不能科学上网,解决办法如下:

A:从阿里云镜像仓库用docker pull 命令 把metrics-server-amd64:v0.3.1下载到本地(注意看调度到哪个node,镜像就放到哪个node上),然后用docker tag 把pull下来的镜像名称修改成k8s.gcr.io/metrics-server-amd64:v0.3.1 即可。

B:修改metrics-server-depoyment.yaml文件的镜像拉取策略为IfNotPresent

---------------报错

E0304 09:14:52.776119 1 reststorage.go:129] unable to fetch node metrics for node "k8s-node2": no metrics known for node

E0304 09:15:03.649147 1 manager.go:102] unable to fully collect metrics: [unable to fully scrape metrics from source kubelet_summary:k8s-node2: unable to fetch metrics from Kubelet k8s-node2 (k8s-node2): Get https://k8s-node2:10250/stats/summary/: dial tcp: lookup k8s-node2 on 10.100.0.10:53: no such host, unable to fully scrape metrics from source kubelet_summary:k8s-master: unable to fetch metrics from Kubelet k8s-master (k8s-master): Get https://k8s-master:10250/stats/summary/: dial tcp: lookup k8s-master on 10.100.0.10:53: no such host, unable to fully scrape metrics from source kubelet_summary:k8s-node1: unable to fetch metrics from Kubelet k8s-node1 (k8s-node1): Get https://k8s-node1:10250/stats/summary/: dial tcp: lookup k8s-node1 on 10.100.0.10:53: no such host]

【提示 无法解析节点的主机名,是metrics-server这个容器不能通过CoreDNS 10.96.0.10:53 解析各Node的主机名,metrics-server连节点时默认是连接节点的主机名,需要加个参数,让它连接节点的IP,同时因为10250是https端口,连接它时需要提供证书,所以加上–kubelet-insecure-tls,表示不验证客户端证书,此前的版本中使用–source=这个参数来指定不验证客户端证书。】

提示 无法解析节点的主机名,是metrics-server这个容器不能通过CoreDNS 10.96.0.10:53 解析各Node的主机名,metrics-server连节点时默认是连接节点的主机名,需要加个参数,让它连接节点的IP:

“–kubelet-preferred-address-types=InternalIP”

因为10250是https端口,连接它时需要提供证书,所以加上–kubelet-insecure-tls,表示不验证客户端证书,此前的版本中使用–source=这个参数来指定不验证客户端证书。

———————

解决方法

yaml文件新加如下配置

[root@k8s-master 1.8+]# vim metrics-server-deployment.yaml

[root@k8s-master 1.8+]#

#add

command:

– /metrics-server

– –kubelet-insecure-tls

– –kubelet-preferred-address-types=InternalIP

----------报错2

[root@k8s-master 1.8+]# kubectl logs -n kube-system pod/metrics-server-6c8b76677-fx5mr

I0304 09:52:24.936032 1 serving.go:273] Generated self-signed cert (apiserver.local.config/certificates/apiserver.crt, apiserver.local.config/certificates/apiserver.key)

[restful] 2019/03/04 09:52:26 log.go:33: [restful/swagger] listing is available at https://:443/swaggerapi

[restful] 2019/03/04 09:52:26 log.go:33: [restful/swagger] https://:443/swaggerui/ is mapped to folder /swagger-ui/

I0304 09:52:26.100866 1 serve.go:96] Serving securely on [::]:443

E0304 09:52:49.743254 1 reststorage.go:129] unable to fetch node metrics for node "k8s-master": no metrics known for node

E0304 09:52:49.743282 1 reststorage.go:129] unable to fetch node metrics for node "k8s-node1": no metrics known for node

E0304 09:52:49.743288 1 reststorage.go:129] unable to fetch node metrics for node "k8s-node2": no metrics known for node

全局需要修改的地方

containers:

– name: metrics-server

image: k8s.gcr.io/metrics-server-amd64:v0.3.1

imagePullPolicy: Never #下面的重复数的注意删除

command:

– /metrics-server

– –kubelet-insecure-tls

– –kubelet-preferred-address-types=InternalIP

文章出自:CCIE那点事 http://www.jdccie.com/ 版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。 禁止全文转载。
本文链接:http://www.jdccie.com/?p=4066转载请注明转自CCIE那点事
如果喜欢:点此订阅本站
  • 相关文章
  • 为您推荐
  • 各种观点

暂时还木有人评论,坐等沙发!
发表评论

您必须 [ 登录 ] 才能发表留言!