k8s kubeedge安装metrics-server监控节点cpu内存使用情况
k8s kubeedge安装metrics-server监控节点cpu内存使用情况
k8s的master节点上安装metrics-server
#在k8s的master节点上执行
#创建目录
mkdir metrics-server
#下载deploy文件
wget https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.4.0/components.yaml -O deploy.yaml
#修改配置如下,可以参考官方的配置
vim deploy.yaml
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/master
operator: Exists
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
hostNetwork: true
containers:
- args:
- --kubelet-insecure-tls
- --cert-dir=/tmp
- --secure-port=4443
#deploy里的镜像需要翻墙下载
docker pull k8s.gcr.io/metrics-server/metrics-server:v0.4.0
#我先本地翻墙,把镜像下载下来然后导过去的
docker save -o metrics-server-image.tar k8s.gcr.io/metrics-server/metrics-server:v0.4.0
docker load -i metrics-server-image.tar
#大家可以在docker hub下载我推上去的镜像
docker push beyondyinjl/metrics-server:v0.4.0
#然后修改镜像名
docker tag beyondyinjl/metrics-server:v0.4.0 k8s.gcr.io/metrics-server/metrics-server:v0.4.0
#应用
kubectl apply -f deploy.yaml
#过一会,等启动成功后,使用命令查看内存CPU情况
kubectl top node
#回显如下:
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
edge-node-1 2100m 52% 1579Mi 42%
k8s-master 1404m 35% 12325Mi 78%
kubeedge节点开启CPU内存的监控
在部署metrics-server之前,kubectl logs必须激活功能
#在云节点上操作:
#用户更改为root
sudo su
#确保您可以找到kubernetes 的ca.crt和ca.key文件
ls /etc/kubernetes/pki/
export CLOUDCOREIPS="192.168.3.100"
echo $CLOUDCOREIPS
cp $GOPATH/src/github.com/kubeedge/kubeedge/build/tools/certgen.sh /etc/kubeedge/
cd /etc/kubeedge/
#从certgen.sh生成证书
/etc/kubeedge/certgen.sh stream
#需要在云主机上设置iptables。(此命令应该在每个apiserver部署的节点上执行。)
iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
iptables -t nat -A OUTPUT -p tcp --dport 10350 -j DNAT --to $CLOUDCOREIPS:10003
#修改云主机 enable: true
vim /etc/kubeedge/config/cloudcore.yaml
cloudStream:
enable: true
streamPort: 10003
tlsStreamCAFile: /etc/kubeedge/ca/streamCA.crt
tlsStreamCertFile: /etc/kubeedge/certs/stream.crt
tlsStreamPrivateKeyFile: /etc/kubeedge/certs/stream.key
tlsTunnelCAFile: /etc/kubeedge/ca/rootCA.crt
tlsTunnelCertFile: /etc/kubeedge/certs/server.crt
tlsTunnelPrivateKeyFile: /etc/kubeedge/certs/server.key
tunnelPort: 10004
#重启cloudcore
systemctl status cloudcore.service
systemctl restart cloudcore.service
#在边缘节点上操作
#修改 enable: true server: 192.168.x.x:10004
vim /etc/kubeedge/config/edgecore.yaml
edgeStream:
enable: true
handshakeTimeout: 30
readDeadline: 15
server: 192.168.3.100:10004
tlsTunnelCAFile: /etc/kubeedge/ca/rootCA.crt
tlsTunnelCertFile: /etc/kubeedge/certs/server.crt
tlsTunnelPrivateKeyFile: /etc/kubeedge/certs/server.key
writeDeadline: 15
#重启edge core
systemctl status edgecore.service
systemctl restart edgecore.service
shell脚本动态替换
#备份一下
cp /etc/kubeedge/config/edgecore.yaml /etc/kubeedge/config/edgecore.yaml.bak
#删除edgeStream的下一行
sed -i '/edgeStream:/{n;d}' /etc/kubeedge/config/edgecore.yaml.bak
#在edgeStream的下一行添加一行: enable: true
sed -i -e '/edgeStream:/{s|$|\n enable: true|}' /etc/kubeedge/config/edgecore.yaml.bak
#删除edgeStream的下第4行
sed -i '/edgeStream:/{n;n;n;n;d}' /etc/kubeedge/config/edgecore.yaml
#在edgeStream的下第3行后添加一行,也就是第4行: server: 192.168.3.100:10004
sed -i -e '/edgeStream:/{n;n;n;s|$|\n server: 192.168.3.100:10004|}' /etc/kubeedge/config/edgecore.yaml
#这里的 server: cloudIp:10004 会原样写入到文件
sed -i -e '/edgeStream:/{n;n;n;s|$|\n server: cloudIp:10004|}' /etc/kubeedge/config/edgecore.yaml
#替换文件中cloudIp为变量$cloudIp的内容如:192.168.3.100
cloudIp=192.168.3.100
sed -i "s/cloudIp/$cloudIp/g" /etc/kubeedge/config/edgecore.yaml