ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[TOC] ## **部署NodeExporter** 创建文件`node-exporter.yaml`,内容如下: ``` apiVersion: apps/v1 kind: DaemonSet metadata: name: node-exporter namespace: kube-system spec: selector: matchLabels: app: node-exporter template: metadata: labels: app: node-exporter spec: containers: - name: node-exporter image: prom/node-exporter imagePullPolicy: IfNotPresent args: - --path.procfs=/host/proc - --path.sysfs=/host/sys volumeMounts: - mountPath: /host/proc name: proc readOnly: true - mountPath: /host/sys name: sys readOnly: true volumes: - name: proc hostPath: path: /proc - name: sys hostPath: path: /sys hostNetwork: true hostPID: true ``` 这里,我们设置让node-exporter容器使用主机网络,这样就可以监控到主机的网卡流量指标。然后把宿主机的`/proc`与`/sys`目录挂载到容器,这样就可以监控主机的磁盘。 ## **更改Prometheus配置** #### **方法一:通过Pod服务发现** 编辑`prometheus-config.yaml`文件,添加如下内容: ``` - job_name: node-exporter kubernetes_sd_configs: - role: pod relabel_configs: - action: keep source_labels: [__meta_kubernetes_pod_label_app] regex: node-exporter - action: replace source_labels: [__meta_kubernetes_pod_ip] regex: (.*) target_label: __address__ replacement: ${1}:9100 ``` 这里我们使用到Kubernetes的Pod服务发现,由于它会发现所有的Pod,所以我们使用`keep`操作,只保留标签中带有`app=node-exporter`的Pod。另外,`__address__`也设置为了`PodIP:9100`。 下面是Pod服务发现的Target的初始标签: ![](https://img.kancloud.cn/d3/00/d30026ff95cf7fb1770abe6b0bec6be7_517x570.png) #### **方法二:通过Node服务发现** ``` - job_name: node-exporter kubernetes_sd_configs: - role: node relabel_configs: - action: replace source_labels: [__meta_kubernetes_node_address_InternalIP] regex: (.*) target_label: __address__ replacement: ${1}:9100 ``` 这种方法的一个好处就是,如果k8s的主机上已经物理部署了node-exporter,那么我们就不需要再部署上面的node-exporter-daemonset,这样就可以避免9100端口的冲突。