赞
踩
实验k8s集群环境如下:
主机名 | 主机ip | 类型 |
---|---|---|
k8s-master | 192.168.56.104 | master |
k8s-node1 | 192.168.56.105 | worker |
k8s-node2 | 192.168.56.106 | worker |
node-exporter介绍:
node-exporter 可以采集机器(物理机、虚拟机、云主机等)的监控指标数据,能够采集到的指标包
括 CPU, 内存,磁盘,网络,文件数等信息。
kubectl create ns monitor-sa
mkdir -p /home/kevin/k8s/prometheus_grafana && cd /home/kevin/k8s/prometheus_grafana
镜像包下载到k8s每个节点prometheus_grafana路径下
链接:https://pan.baidu.com/s/115CF-0IV0cg72upv2WR36Q
提取码:79xj
加载k8s每个节点的node-exporter镜像包
docker load -i node-exporter.tar.gz
下载部署文件node-export.yaml到k8s控制节点k8s-master上
链接:https://pan.baidu.com/s/1QGMvqArDM8vElw3C3vLrTA
提取码:tgsp
[root@k8s-master prometheus_grafana]# cat node-export.yaml apiVersion: apps/v1 kind: DaemonSet # 可以保证 k8s 集群的每个节点都运行完全一样的 pod metadata: name: node-exporter namespace: monitor-sa labels: name: node-exporter spec: selector: matchLabels: name: node-exporter template: metadata: labels: name: node-exporter spec: hostPID: true hostIPC: true hostNetwork: true # hostNetwork、 hostIPC、 hostPID 都为 True 时: # 表示这个 Pod 里的所有容器,会直接使用宿主机的网络, # 直接与宿主机进行 IPC(进程间通信) 通信, # 可以看到宿主机里正在运行的所有进程。 # 加入了 hostNetwork:true 会直接将我们的宿主机的 9100 端口映射出来, # 从而不需要创建 service 在我们的宿主机上就会有一个 9100 的端口 containers: - name: node-exporter image: prom/node-exporter:v0.16.0 ports: - containerPort: 9100 resources: requests: cpu: 0.15 # 这个容器运行至少需要 0.15 核 cpu securityContext: privileged: true # 开启特权模式 args: - --path.procfs # 配置挂载宿主机(node节点)的路径 - /host/proc - --path.sysfs # 配置挂载宿主机(node节点)的路径 - /host/sys - --collector.filesystem.ignored-mount-points - '"^/(sys|proc|dev|host|etc)($|/)"' # 通过正则表达式忽略某些文件系统挂载点的信息收集 volumeMounts: - name: dev mountPath: /host/dev - name: proc mountPath: /host/proc - name: sys mountPath: /host/sys - name: rootfs mountPath: /rootfs # 将主机/dev、 /proc、 /sys 这些目录挂在到容器中, # 这是因为我们采集的很多节点数据都是通过这些文件来获取系统信息的 tolerations: - key: "node-role.kubernetes.io/master" operator: "Exists" effect: "NoSchedule" volumes: - name: proc hostPath: path: /proc - name: dev hostPath: path: /dev - name: sys hostPath: path: /sys - name: rootfs hostPath: path: /
[root@k8s-master]# kubectl apply -f node-export.yaml
显示如下,看到 pod 的状态都是 Running,说明部署成功
[root@k8s-master]# kubectl get pods -n monitor-sa
NAME READY STATUS RESTARTS AGE
node-exporter-84tk7 1/1 Running 4 2d
node-exporter-ctmks 1/1 Running 9 2d
node-exporter-jzg8t 1/1 Running 2 2d
查看k8s控制节点192.168.56.104的指标
[root@k8s-master prometheus_grafana]# curl http://192.168.56.104:9100/metrics # HELP go_gc_duration_seconds A summary of the GC invocation durations. # TYPE go_gc_duration_seconds summary go_gc_duration_seconds{quantile="0"} 0 go_gc_duration_seconds{quantile="0.25"} 0 go_gc_duration_seconds{quantile="0.5"} 0 go_gc_duration_seconds{quantile="0.75"} 0 go_gc_duration_seconds{quantile="1"} 0 go_gc_duration_seconds_sum 0 go_gc_duration_seconds_count 0 # HELP go_goroutines Number of goroutines that currently exist. # TYPE go_goroutines gauge go_goroutines 7 # HELP go_info Information about the Go environment. # TYPE go_info gauge go_info{version="go1.9.6"} 1 # HELP go_memstats_alloc_bytes Number of bytes allocated and still in use. # TYPE go_memstats_alloc_bytes gauge go_memstats_alloc_bytes 1.333648e+06 ......
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。