Laf 集群监控基石:prometheus-node-exporter Helm Chart 完整部署与配置指南
发布时间:2026/9/16 18:32:43 作者:尧图编辑部 阅读量:1,286

Laf 集群监控基石prometheus-node-exporter Helm Chart 完整部署与配置指南【免费下载链接】lafLaf is a vibrant cloud development platform that provides essential tools like cloud functions, databases, and storage solutions. It enables developers to quickly unleash their creativity and bring innovative ideas to life with ease.项目地址: https://gitcode.com/GitHub_Trending/la/laf导读本文以 Laf 开源云开发平台仓库内build/charts/kube-prometheus-stack图表集所依赖的prometheus-node-exporterHelm Chart 为主体系统讲解如何在 Kubernetes 集群上通过 Helm 部署 node-exporter、配置其采集行为、启用 kube-rbac-proxy 端点保护以及对接 ServiceMonitor / PodMonitor 实现节点级硬件与操作系统指标采集。读完本文你将掌握该 Chartv4.21.0node-exporter v1.6.0的安装、升级、核心 values 调优与底层 DaemonSet 实现原理并能在自有监控栈中直接复用以完成集群节点可观测性建设。一、图表定位它在 Laf 项目与监控体系中的角色prometheus-node-exporter是 Prometheus 官方生态中的核心组件其职责是采集 *NIX 内核暴露的硬件与操作系统指标CPU、内存、磁盘、网络、文件系统等并以 HTTP/metrics端点对外提供 Prometheus 文本格式的数据。项目自身采用 Go 语言编写指标采集器collector采用可插拔设计可按需启用或禁用。在本仓库中该图表以依赖子图的形式被 Vendored 在监控基础设施目录下图表主体build/charts/kube-prometheus-stack/charts/prometheus-node-exporter/README.md图表元数据build/charts/kube-prometheus-stack/charts/prometheus-node-exporter/Chart.yamlname: prometheus-node-exporterversion: 4.21.0appVersion: 1.6.0type: applicationApache-2.0 许可从 Chart.yaml 可知当前默认对应的 node-exporter 二进制版本为1.6.0默认镜像为quay.io/prometheus/node-exportertag 缺省时取v{{ .Chart.AppVersion }}即v1.6.0见 _helpers.tpl 中prometheus-node-exporter.image的定义。作为 DaemonSet 形态的采集器它会在每个节点上运行一个 Pod配合hostNetwork、hostPID以及宿主机/proc、/sys、根文件系统挂载直接读取节点级指标。这也是 Kubernetes 集群“节点可观测性”最标准、最轻量的方案。二、快速上手仓库信息、安装、卸载与升级2.1 添加 Helm 仓库并更新索引在具备 Helm 的环境下先添加官方社区仓库并刷新索引helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update2.2 安装 Charthelm install [RELEASE_NAME] prometheus-community/prometheus-node-exporter安装后将得到一个以[RELEASE_NAME]命名的 Release并默认创建 DaemonSet、Service、ServiceAccount 等 Kubernetes 资源具体资源清单见下文源码剖析。2.3 卸载 Charthelm uninstall [RELEASE_NAME]该命令会移除与此 Chart 关联的所有 Kubernetes 组件并删除整个 Release。2.4 升级 Charthelm upgrade [RELEASE_NAME] [CHART] --install--install表示如果 Release 尚不存在则直接执行安装适合在 CI/CD 中幂等执行。2.5 查看全部可配置项helm show values prometheus-community/prometheus-node-exporter本地开发时可直接阅读仓库内带详细注释的默认值文件 values.yaml。三、升级注意事项跨大版本必读3.1 4.16 升级到 4.17从 4.17 开始containerSecurityContext.readOnlyRootFilesystem默认值被设置为true见 values.yaml 第 273-274 行。如果你的自定义配置覆盖了容器安全上下文升级后请确认容器根文件系统只读不会影响挂载的采集路径。3.2 3.x 升级到 4.x从4.0.0起该 Chart 全面采用 Kubernetes 推荐标签体系app.kubernetes.io/name、app.kubernetes.io/instance、app.kubernetes.io/version等。由于标签变化会导致新旧 DaemonSet 并存或选择器不匹配升级前必须先删除旧 DaemonSetkubectl delete daemonset -l appprometheus-node-exporter helm upgrade -i prometheus-node-exporter prometheus-community/prometheus-node-exporter如果你使用自定义的 ServiceMonitor 或 PodMonitor请同步升级其selector字段以匹配新标签。图表自身生成的选择器标签定义在 _helpers.tpl 的prometheus-node-exporter.selectorLabels中为app.kubernetes.io/name与app.kubernetes.io/instance的组合。3.3 2.x 升级到 3.x2.x 中启用宿主机根文件系统挂载的写法为hostRootFsMount: true3.x 起必须改写为对象形式以同时控制挂载传播模式hostRootFsMount: enabled: true mountPropagation: HostToContainermountPropagation的取值与 Kubernetes 卷挂载传播语义一致None、HostToContainer、Bidirectional缺省为None当前 Chart 默认值即HostToContainer见 values.yaml 第 299-306 行。四、核心配置values.yaml 深度解读以下按功能域拆解 values.yaml 中的关键参数。4.1 镜像与拉取策略参数默认值说明image.registryquay.io镜像仓库主机名可用global.imageRegistry覆盖image.repositoryprometheus/node-exporter镜像仓库路径image.tag缺省取v1.6.0显式覆盖镜像版本image.pullPolicyIfNotPresent拉取策略image.digest指定 digest 以锁定不可变镜像imagePullSecrets/global.imagePullSecrets[]私有仓库拉取凭据兼容 map 与字符串两种写法镜像拼接逻辑在 _helpers.tpl 的prometheus-node-exporter.image中实现优先global.imageRegistrytag 缺省为v{AppVersion}并支持 digest 锁定。4.2 服务暴露参数默认值说明service.typeClusterIP服务类型service.port9100Service 端口service.targetPort9100目标容器端口service.nodePort空仅当type: NodePort时生效service.portNamemetrics端口名称ServiceMonitor 以此引用service.listenOnAllInterfacestrue监听全部接口0.0.0.0否则绑定宿主机 IPservice.ipDualStack禁用启用 IPv4/IPv6 双栈ipFamilies默认[IPv6, IPv4]策略PreferDualStackService 模板见 service.yaml默认携带注解prometheus.io/scrape: true便于传统 Prometheus 注解发现。ci/port-values.yaml展示了通过覆盖service.port与service.targetPort自定义端口的 CI 用例。4.3 宿主机访问与采集路径参数默认值说明hostNetworktrue使用宿主机网络命名空间hostPIDtrue共享宿主机 PID 命名空间hostRootFsMount.enabledtrue将宿主机/挂载到容器/host/roothostRootFsMount.mountPropagationHostToContainer挂载传播模式extraArgs[]追加 node-exporter 二进制启动参数结合 daemonset.yaml容器默认启动参数为--path.procfs/host/proc --path.sysfs/host/sys --path.rootfs/host/root --path.udev.data/host/root/run/udev/data # 仅当 node-exporter 1.4.0 --web.listen-address[$(HOST_IP)]:9100其中HOST_IP环境变量的取值策略启用 kube-rbac-proxy 时为127.0.0.1否则若service.listenOnAllInterfaces为true则取0.0.0.0反之取status.hostIP宿主机 IP。常见extraArgs示例如屏蔽部分磁盘设备、启用 textfile 采集器extraArgs: - --collector.diskstats.ignored-devices^(ram|loop|fd|(h|s|v)d[a-z]|nvme\dn\dp)\d$ - --collector.textfile.directory/run/prometheus4.4 安全上下文与 RBAC参数默认值说明securityContextrunAsUser/runAsGroup/fsGroup: 65534runAsNonRoot: truePod 级安全上下文65534 即nobodycontainerSecurityContext.readOnlyRootFilesystemtrue容器根文件系统只读4.17 默认serviceAccount.createtrue自动创建 ServiceAccountrbac.createtrue创建 RBAC 资源rbac.pspEnabledtrue创建 Pod Security Policy 相关资源注意 daemonset.yaml 中的细节automountServiceAccountToken仅在serviceAccount.automountServiceAccountToken或启用kubeRBACProxy时为true避免默认情况下无谓地把集群凭证注入到每个节点的采集器容器中。4.5 调度与生命周期参数默认值说明nodeSelectorkubernetes.io/os: linux仅调度到 Linux 节点tolerationsNoSchedule且operator: Exists容忍所有污点确保覆盖每个节点updateStrategyRollingUpdatemaxUnavailable: 1DaemonSet 滚动更新策略livenessProbe/readinessProbehttpGet /periodSeconds: 10timeoutSeconds: 1failureThreshold: 3存活/就绪探针路径为/而非/metricsaffinity/priorityClassName/dnsConfig空/空/空高级调度与 DNS 定制4.6 扩展挂载、Sidecar 与额外清单extraHostVolumeMounts从宿主机额外挂载路径到 node-exporter 容器可自定义mountPropagation。configmaps/secrets向容器挂载配置与密钥。sidecars/sidecarVolumeMount/sidecarHostVolumeMounts注入旁路容器如nvidia-dcgm-exporter及其挂载。extraInitContainers初始化容器。extraManifests以数组形式追加任意 Kubernetes 清单如额外 ConfigMap由 extra-manifests.yaml 渲染。endpoints当 node-exporter 部署在集群外部时手动列出其地址供 Service 引用。verticalPodAutoscaler默认关闭开启后可配置maxAllowed/minAllowed/updatePolicy等。networkPolicy默认关闭开启后仅允许 Service 端口的入站流量且禁止出站模板见 networkpolicy.yaml。五、端点安全保护kube-rbac-proxy 集成5.1 启用方式将kubeRBACProxy.enabled设为trueChart 会在 DaemonSet 中追加一个kube-rbac-proxy容器镜像默认quay.io/brancz/kube-rbac-proxy:v0.14.0保护 node-exporter 的 HTTP 端点请求经同一 Service 转发但改为HTTPS详见 daemonset.yaml 第 181-220 行。启用后内部端口联动node-exporter 容器监听8100由$servicePort : ternary 8100 .Values.service.port .Values.kubeRBACProxy.enabled决定kube-rbac-proxy 以--secure-listen-address:9100对外提供 HTTPS并--upstreamhttp://127.0.0.1:8100/反代到本机采集端点同时暴露8888端口的healthz就绪检查。RBAC 授权由 rbac-configmap.yaml 生成的 ConfigMap 提供kube-rbac-proxy 以resourceAttributes模式校验请求者对被保护 Service 的get权限。5.2 授权访问示例要访问被保护的端点请求方例如一个 ServiceAccount需要被授予类似下面的 ClusterRoleapiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: prometheus-node-exporter-read rules: - apiGroups: [ ] resources: [services/node-exporter-prometheus-node-exporter] verbs: - get其中resources中的名称需替换为你实际的 Service 全名release-prometheus-node-exporter。同时图表自身在启用该功能时会创建 ClusterRole见 clusterrole.yaml为 kube-rbac-proxy 授予tokenreviews与subjectaccessreviews的create权限这是其完成身份认证与鉴权的前提。更丰富的用法可参考 kube-rbac-proxy 官方的resource-attributes示例。5.3 相关可调参数kubeRBACProxy.extraArgs可追加额外 CLI 参数如 TLS 密码套件、日志文件kubeRBACProxy.resources与kubeRBACProxy.containerSecurityContext可分别定制代理容器的资源与安全上下文。六、对接 PrometheusServiceMonitor 与 PodMonitor 双通道6.1 ServiceMonitor推荐启用prometheus: monitor: enabled: true模板见 servicemonitor.yaml渲染出的资源默认使用monitoring.coreos.com/v1API 版本关键字段包括jobLabel默认app.kubernetes.io/namepodTargetLabels把 Pod 标签转移到目标上可用于携带节点相关信息scheme默认http启用 kube-rbac-proxy 时应改为https并配置tlsConfig/authorizationbasicAuth/bearerTokenFile抓取时的认证方式interval/scrapeTimeout默认抓取间隔跟随 Prometheus 全局配置scrapeTimeout默认10sattachMetadata.node: true把节点元数据附加到发现的目标要求 Prometheus ≥ 2.35.0抓取限额sampleLimit、targetLimit、labelLimit、labelNameLengthLimit、labelValueLengthLimit由 _helpers.tpl 中的servicemonitor.scrapeLimits模板渲染relabelings/metricRelabelings抓取前/入库前的标签重写。6.2 PodMonitor大规模集群场景对于 node-exporter 端点数量极多如超过 1000 个的环境可改用 PodMonitor 绕过单一 Service 的聚合模板见 podmonitor.yamlprometheus: podMonitor: enabled: truePodMonitor 默认以/metrics路径、httpscheme 抓取并额外提供honorTimestamps、honorLabels、enableHttp2、filterRunning、followRedirects、params、authorization、oauth2等 endpoint 级选项。切换注意从 ServiceMonitor 切到 PodMonitor 后时间序列不再携带service标签依赖该标签的 PromQL 查询需要同步调整。6.3 标签联动releaseLabel 的作用若你的 Prometheus 通过release: name标签选择 ServiceMonitorkube-prometheus-stack 的常见做法可将releaseLabel: true打开让图表在资源标签中加入release: {{ .Release.Name }}从而开箱即用地被 kube-prometheus-stack 抓取。七、Laf 项目中的实际落地方式在本仓库中该 Chart 作为 build/charts/kube-prometheus-stack 整套监控图表集的一个依赖子图被管理。父图表 build/charts/kube-prometheus-stack/values.yaml第 1887 行起展示了在 Laf 部署场景下的典型覆盖配置prometheus-node-exporter: namespaceOverride: podLabels: jobLabel: node-exporter releaseLabel: true extraArgs: - --collector.filesystem.mount-points-exclude^/(dev|proc|sys|var/lib/docker/.|var/lib/kubelet/.)($|/)要点解读podLabels.jobLabel: node-exporter为 Pod 打上jobLabel: node-exporter标签使 ServiceMonitor 发现后生成的 job 名与官方告警规则、Grafana 大盘中的jobnode-exporter查询习惯保持一致releaseLabel: true确保 ServiceMonitor 携带release标签可直接被 kube-prometheus-stack 的默认选择器命中extraArgs中的挂载点排除规则过滤掉/dev、/proc、/sys、Docker 与 kubelet 数据目录下的伪文件系统挂载点避免文件系统指标出现海量噪声这是生产集群非常实用的瘦身技巧。八、从模板到资源一次 Helm 渲染会产出什么根据templates/目录该 Chart 默认渲染的 Kubernetes 资源包括模板文件资源说明daemonset.yamlDaemonSet核心工作负载每节点一个 Podservice.yamlService暴露 9100 端口的ClusterIP服务serviceaccount.yamlServiceAccount采集器身份clusterrole.yamlClusterRole启用 kube-rbac-proxy 时的鉴权权限clusterrolebinding.yamlClusterRoleBinding绑定上述角色servicemonitor.yamlServiceMonitor开启prometheus.monitor.enabled时创建podmonitor.yamlPodMonitor开启prometheus.podMonitor.enabled时创建endpoints.yamlEndpoints配置endpoints时创建指向集群外采集器psp.yaml 等PodSecurityPolicyrbac.pspEnabled为true时创建PSP 已废弃的旧集群适用networkpolicy.yamlNetworkPolicynetworkPolicy.enabled时创建verticalpodautoscaler.yamlVerticalPodAutoscalerverticalPodAutoscaler.enabled时创建extra-manifests.yaml自定义透传extraManifests数组内容从 daemonset.yaml 的卷定义可以看出其“直读宿主机”的核心机制/proc、/sys以hostPath方式挂载宿主机根目录/以只读方式挂载到/host/root配合hostPID: true与hostNetwork: true使每个节点上的 node-exporter 都能以最小的权限面读取完整的系统指标。九、运维最佳实践小结控制指标噪声通过extraArgs排除容器运行时与 kubelet 数据目录的挂载点、忽略ram/loop/fd等虚拟磁盘设备可显著降低基数与存储成本。按需关闭默认开启项rbac.pspEnabled在已启用 Pod Security Admission 的新集群可关闭hostNetwork在强调网络隔离的环境可按需评估。安全抓取优先生产环境建议开启kubeRBACProxy.enabled并以httpstlsConfig或authorization方式对接 ServiceMonitor配合上文的最小权限 ClusterRole 完成鉴权。升级前做标签审计跨 3.x → 4.x 升级必须删除旧 DaemonSet并同步检查自定义 ServiceMonitor/PodMonitor 的 selector。验证抓取链路安装后先kubectl get daemonset确认每节点就绪再直接curl节点 9100 端口的/metrics或/探针路径验证采集端点健康最后确认 Prometheus 侧 ServiceMonitor 的目标列表。结合 Laf 仓库中父图表的调优案例jobLabel: node-exporter与挂载点排除规则这套方案可以直接作为自建集群“节点级可观测性”的标准化模板投入使用。【免费下载链接】lafLaf is a vibrant cloud development platform that provides essential tools like cloud functions, databases, and storage solutions. It enables developers to quickly unleash their creativity and bring innovative ideas to life with ease.项目地址: https://gitcode.com/GitHub_Trending/la/laf创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考