vlambda博客
学习文章列表

k8s kubeedge安装metrics-server监控节点cpu内存使用情况

k8s kubeedge安装metrics-server监控节点cpu内存使用情况

k8s的master节点上安装metrics-server

 
   
   
 
  1. #在k8s的master节点上执行


  2. #创建目录

  3. mkdir metrics-server


  4. #下载deploy文件

  5. wget https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.4.0/components.yaml -O deploy.yaml


  6. #修改配置如下,可以参考官方的配置

  7. vim deploy.yaml

  8. spec:

  9. affinity:

  10. nodeAffinity:

  11. requiredDuringSchedulingIgnoredDuringExecution:

  12. nodeSelectorTerms:

  13. - matchExpressions:

  14. - key: node-role.kubernetes.io/master

  15. operator: Exists

  16. tolerations:

  17. - key: node-role.kubernetes.io/master

  18. operator: Exists

  19. effect: NoSchedule

  20. hostNetwork: true



  21. containers:

  22. - args:

  23. - --kubelet-insecure-tls

  24. - --cert-dir=/tmp

  25. - --secure-port=4443


  26. #deploy里的镜像需要翻墙下载

  27. docker pull k8s.gcr.io/metrics-server/metrics-server:v0.4.0


  28. #我先本地翻墙,把镜像下载下来然后导过去的

  29. docker save -o metrics-server-image.tar k8s.gcr.io/metrics-server/metrics-server:v0.4.0

  30. docker load -i metrics-server-image.tar


  31. #大家可以在docker hub下载我推上去的镜像

  32. docker push beyondyinjl/metrics-server:v0.4.0

  33. #然后修改镜像名

  34. docker tag beyondyinjl/metrics-server:v0.4.0 k8s.gcr.io/metrics-server/metrics-server:v0.4.0


  35. #应用

  36. kubectl apply -f deploy.yaml


  37. #过一会,等启动成功后,使用命令查看内存CPU情况

  38. kubectl top node

  39. #回显如下:

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

  41. edge-node-1 2100m 52% 1579Mi 42%

  42. k8s-master 1404m 35% 12325Mi 78%

kubeedge节点开启CPU内存的监控

在部署metrics-server之前,kubectl logs必须激活功能

 
   
   
 
  1. #在云节点上操作:


  2. #用户更改为root

  3. sudo su


  4. #确保您可以找到kubernetes 的ca.crt和ca.key文件

  5. ls /etc/kubernetes/pki/


  6. export CLOUDCOREIPS="192.168.3.100"

  7. echo $CLOUDCOREIPS


  8. cp $GOPATH/src/github.com/kubeedge/kubeedge/build/tools/certgen.sh /etc/kubeedge/

  9. cd /etc/kubeedge/


  10. #从certgen.sh生成证书

  11. /etc/kubeedge/certgen.sh stream


  12. #需要在云主机上设置iptables。(此命令应该在每个apiserver部署的节点上执行。)

  13. iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X

  14. iptables -t nat -A OUTPUT -p tcp --dport 10350 -j DNAT --to $CLOUDCOREIPS:10003


  15. #修改云主机 enable: true

  16. vim /etc/kubeedge/config/cloudcore.yaml


  17. cloudStream:

  18. enable: true

  19. streamPort: 10003

  20. tlsStreamCAFile: /etc/kubeedge/ca/streamCA.crt

  21. tlsStreamCertFile: /etc/kubeedge/certs/stream.crt

  22. tlsStreamPrivateKeyFile: /etc/kubeedge/certs/stream.key

  23. tlsTunnelCAFile: /etc/kubeedge/ca/rootCA.crt

  24. tlsTunnelCertFile: /etc/kubeedge/certs/server.crt

  25. tlsTunnelPrivateKeyFile: /etc/kubeedge/certs/server.key

  26. tunnelPort: 10004


  27. #重启cloudcore

  28. systemctl status cloudcore.service

  29. systemctl restart cloudcore.service

 
   
   
 
  1. #在边缘节点上操作


  2. #修改 enable: true server: 192.168.x.x:10004

  3. vim /etc/kubeedge/config/edgecore.yaml

  4. edgeStream:

  5. enable: true

  6. handshakeTimeout: 30

  7. readDeadline: 15

  8. server: 192.168.3.100:10004

  9. tlsTunnelCAFile: /etc/kubeedge/ca/rootCA.crt

  10. tlsTunnelCertFile: /etc/kubeedge/certs/server.crt

  11. tlsTunnelPrivateKeyFile: /etc/kubeedge/certs/server.key

  12. writeDeadline: 15


  13. #重启edge core

  14. systemctl status edgecore.service

  15. systemctl restart edgecore.service

shell脚本动态替换

 
   
   
 
  1. #备份一下

  2. cp /etc/kubeedge/config/edgecore.yaml /etc/kubeedge/config/edgecore.yaml.bak


  3. #删除edgeStream的下一行

  4. sed -i '/edgeStream:/{n;d}' /etc/kubeedge/config/edgecore.yaml.bak


  5. #在edgeStream的下一行添加一行: enable: true

  6. sed -i -e '/edgeStream:/{s|$|\n enable: true|}' /etc/kubeedge/config/edgecore.yaml.bak


  7. #删除edgeStream的下第4行

  8. sed -i '/edgeStream:/{n;n;n;n;d}' /etc/kubeedge/config/edgecore.yaml


  9. #在edgeStream的下第3行后添加一行,也就是第4行: server: 192.168.3.100:10004

  10. sed -i -e '/edgeStream:/{n;n;n;s|$|\n server: 192.168.3.100:10004|}' /etc/kubeedge/config/edgecore.yaml


  11. #这里的 server: cloudIp:10004 会原样写入到文件

  12. sed -i -e '/edgeStream:/{n;n;n;s|$|\n server: cloudIp:10004|}' /etc/kubeedge/config/edgecore.yaml


  13. #替换文件中cloudIp为变量$cloudIp的内容如:192.168.3.100

  14. cloudIp=192.168.3.100

  15. sed -i "s/cloudIp/$cloudIp/g" /etc/kubeedge/config/edgecore.yaml