k8s kubeedge 装置 metrics-server 监控节点 cpu 内存应用状况
官网装置地址: https://kubeedge.io/en/docs/a…
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 内存的监控
官网文档地址: https://github.com/kubeedge/k…
在部署 metrics-server 之前,kubectl logs 必须激活性能
# 在云节点上操作:
#用户更改为 root
sudo su
#确保您能够找到 kubernetes 的 ca.crt 和 ca.key 文件
ls /etc/kubernetes/pki/
#设置环境 CLOUDCOREIPS。环境变量设置为指定 cloudcore 的 IP 地址
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