监控节点健康状况
节点问题检测器是一个用于监视和报告节点运行状况的守护程序。你可以将节点问题检测器作为 DaemonSet
或独立守护程序运行。节点问题检测器从各种守护程序收集有关节点问题的信息,并将这些状况作为节点状况或作为事件报告给 API 服务器。
要了解如何安装和使用节点问题检测器,请参阅节点问题检测器项目文档。
开始之前
你需要有一个 Kubernetes 集群,并且必须配置 kubectl 命令行工具以与你的集群通信。建议在至少有两个不充当控制平面主机的节点的集群上运行本教程。 如果你还没有集群,可以使用 minikube 创建一个,或者你可以使用以下 Kubernetes Playground 之一
局限性
- 节点问题检测器使用内核日志格式来报告内核问题。要了解如何扩展内核日志格式,请参阅添加对其他日志格式的支持。
启用节点问题检测器
一些云提供商启用节点问题检测器作为插件。你也可以使用 kubectl
或通过创建插件 DaemonSet 来启用节点问题检测器。
使用 kubectl 启用节点问题检测器
kubectl
提供了对节点问题检测器最灵活的管理。你可以覆盖默认配置以使其适合你的环境或检测自定义节点问题。例如
创建一个类似于
node-problem-detector.yaml
的节点问题检测器配置apiVersion: apps/v1 kind: DaemonSet metadata: name: node-problem-detector-v0.1 namespace: kube-system labels: k8s-app: node-problem-detector version: v0.1 kubernetes.io/cluster-service: "true" spec: selector: matchLabels: k8s-app: node-problem-detector version: v0.1 kubernetes.io/cluster-service: "true" template: metadata: labels: k8s-app: node-problem-detector version: v0.1 kubernetes.io/cluster-service: "true" spec: hostNetwork: true containers: - name: node-problem-detector image: registry.k8s.io/node-problem-detector:v0.1 securityContext: privileged: true resources: limits: cpu: "200m" memory: "100Mi" requests: cpu: "20m" memory: "20Mi" volumeMounts: - name: log mountPath: /log readOnly: true volumes: - name: log hostPath: path: /var/log/
注意
你应该验证系统日志目录是否适合你的操作系统发行版。使用
kubectl
启动节点问题检测器kubectl apply -f https://k8s.io/examples/debug/node-problem-detector.yaml
使用插件 Pod 启用节点问题检测器
如果你正在使用自定义集群引导解决方案,并且不需要覆盖默认配置,则可以利用插件 Pod 来进一步自动化部署。
创建 node-problem-detector.yaml
,并将配置保存在控制平面节点上的插件 Pod 的目录 /etc/kubernetes/addons/node-problem-detector
中。
覆盖配置
当构建节点问题检测器的 Docker 镜像时,会嵌入默认配置。
但是,你可以使用 ConfigMap
来覆盖配置
更改
config/
中的配置文件创建
ConfigMap
node-problem-detector-config
kubectl create configmap node-problem-detector-config --from-file=config/
更改
node-problem-detector.yaml
以使用ConfigMap
apiVersion: apps/v1 kind: DaemonSet metadata: name: node-problem-detector-v0.1 namespace: kube-system labels: k8s-app: node-problem-detector version: v0.1 kubernetes.io/cluster-service: "true" spec: selector: matchLabels: k8s-app: node-problem-detector version: v0.1 kubernetes.io/cluster-service: "true" template: metadata: labels: k8s-app: node-problem-detector version: v0.1 kubernetes.io/cluster-service: "true" spec: hostNetwork: true containers: - name: node-problem-detector image: registry.k8s.io/node-problem-detector:v0.1 securityContext: privileged: true resources: limits: cpu: "200m" memory: "100Mi" requests: cpu: "20m" memory: "20Mi" volumeMounts: - name: log mountPath: /log readOnly: true - name: config # Overwrite the config/ directory with ConfigMap volume mountPath: /config readOnly: true volumes: - name: log hostPath: path: /var/log/ - name: config # Define ConfigMap volume configMap: name: node-problem-detector-config
使用新的配置文件重新创建节点问题检测器
# If you have a node-problem-detector running, delete before recreating kubectl delete -f https://k8s.io/examples/debug/node-problem-detector.yaml kubectl apply -f https://k8s.io/examples/debug/node-problem-detector-configmap.yaml
注意
此方法仅适用于使用kubectl
启动的节点问题检测器。如果节点问题检测器作为集群插件运行,则不支持覆盖配置。插件管理器不支持 ConfigMap
。
问题守护程序
问题守护程序是节点问题检测器的子守护程序。它会监视特定类型的节点问题,并将它们报告给节点问题检测器。有几种类型的受支持的问题守护程序。
SystemLogMonitor
类型的守护程序会监视系统日志,并根据预定义的规则报告问题和指标。你可以自定义不同日志源的配置,例如 filelog、kmsg、kernel、abrt 和 systemd。SystemStatsMonitor
类型的守护程序会收集各种与健康相关的系统统计信息作为指标。你可以通过更新其配置文件来定制其行为。CustomPluginMonitor
类型的守护程序通过运行用户定义的脚本来调用和检查各种节点问题。你可以使用不同的自定义插件监视器来监视不同的问题,并通过更新 配置文件来定制守护程序的行为。HealthChecker
类型的守护程序检查节点上 kubelet 和容器运行时的健康状况。
添加对其他日志格式的支持
系统日志监视器当前支持基于文件的日志、journald 和 kmsg。可以通过实现新的日志监视器来添加其他源。
添加自定义插件监视器
你可以通过开发自定义插件来扩展节点问题检测器以执行任何以任何语言编写的监视器脚本。监视器脚本必须符合退出代码和标准输出中的插件协议。有关更多信息,请参阅插件接口提案。
导出器
导出器会将节点问题和/或指标报告给某些后端。支持以下导出器
Kubernetes 导出器:此导出器将节点问题报告给 Kubernetes API 服务器。临时问题报告为事件,永久问题报告为节点状况。
Prometheus 导出器:此导出器会在本地以 Prometheus(或 OpenMetrics)指标的形式报告节点问题和指标。你可以使用命令行参数指定导出器的 IP 地址和端口。
Stackdriver 导出器:此导出器将节点问题和指标报告给 Stackdriver Monitoring API。可以使用配置文件自定义导出行为。
建议和限制
建议在你的集群中运行节点问题检测器以监视节点运行状况。运行节点问题检测器时,你可能需要预期每个节点上的额外资源开销。通常这很好,因为
- 内核日志增长相对缓慢。
- 为节点问题检测器设置了资源限制。
- 即使在高负载下,资源使用量也是可以接受的。有关更多信息,请参阅节点问题检测器基准测试结果。