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

來源:本站原創 Docker 超過2,802 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

好像沒用,自己找個可用源吧

[[email protected] 1.8+]# grep gcr *

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

[[email protected] 1.8+]# vim metrics-server-deployment.yaml

[[email protected] 1.8+]# grep amd64 *

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

[[email protected] 1.8+]#

381 kubectl apply -f ./

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

演示

[[email protected] 1.8+]# kubectl api-versions |grep me

metrics.k8s.io/v1beta1

[[email protected] 1.8+]#

[[email protected] 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%

[[email protected] 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文件新加如下配置

[[email protected] 1.8+]# vim metrics-server-deployment.yaml

[[email protected] 1.8+]#

#add

command:

– /metrics-server

– –kubelet-insecure-tls

– –kubelet-preferred-address-types=InternalIP

----------報錯2

[[email protected] 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.qdxgqk.live/ 版權所有。本站文章除注明出處外,皆為作者原創文章,可自由引用,但請注明來源。 禁止全文轉載。
本文鏈接:http://www.qdxgqk.live/?p=4066轉載請注明轉自CCIE那點事
如果喜歡:點此訂閱本站
  • 相關文章
  • 為您推薦
  • 各種觀點
?
暫時還木有人評論,坐等沙發!
發表評論

您必須 [ 登錄 ] 才能發表留言!

?
?
萌宠夺宝游戏