node-exporter安装
发布日期:2021-05-08 06:01:22 浏览次数:19 分类:精选文章

本文共 2763 字,大约阅读时间需要 9 分钟。

Node-Exporter部署与Prometheus集成指南

1. Node-Exporter部署

node-exporter是一款强大的系统资源监控工具,在Kubernetes生态中发挥着重要作用。本文将指导你如何在Kubernetes集群中部署node-exporter,并进行基本配置。

部署步骤

  • 部署YAML文件

    创建一个名为node-exporter.yaml的文件,填写以下内容:

    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
    name: node-exporter
    namespace: default
    labels:
    name: node-exporter
    spec:
    selector:
    matchLabels:
    name: node-exporter
    template:
    metadata:
    labels:
    name: node-exporter
    spec:
    hostPID: true
    hostIPC: true
    hostNetwork: true
    containers:
    - name: node-exporter
    image: prom/node-exporter:v1.0.1
    ports:
    - containerPort: 9100
    resources:
    requests:
    cpu: 0.15
    securityContext:
    privileged: true
    args:
    - --path.procfs
    - /host/proc
    - --path.sysfs
    - /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
    tolerations:
    - key: "node-role.kubernetes.io/master"
    operator: "Exists"
    effect: "NoSchedule"
    volumes:
    - name: proc
    hostPath: /proc
    - name: dev
    hostPath: /dev
    - name: sys
    hostPath: /sys
    - name: rootfs
    hostPath: /
  • 应用配置文件

    使用kubectl命令应用上述YAML文件:

    kubectl apply -f node-exporter.yaml
  • 验证部署

    部署完成后,可以通过以下命令查看node-exporter的运行状态:

    kubectl get pods -n default -l name=node-exporter

    2. 查看Node-Exporter使用的IP

    要查看node-exporter服务的IP地址,可以使用以下命令:

    kubectl get pods -o wide

    此时会显示所有节点的IP地址,包括node-exporter的服务IP。

    3. Prometheus中配置Node-Exporter

    在Prometheus中配置node-exporter作为数据源,可以通过以下步骤完成:

  • 配置Prometheus YAML文件

    打开Prometheus配置文件(例如prometheus.yml),找到scrape_configs部分,添加以下内容:

    - job_name: node-exporter
    honor_timestamps: true
    scrape_interval: 30s
    scrape_timeout: 10s
    metrics_path: /metrics
    scheme: http
    static_configs:
    - targets:
    - 192.168.39.170:9100
  • 保存并应用配置

    确保配置文件路径正确,然后应用修改:

    kubectl apply -f prometheus.yml
  • 注意事项

    • 版本更新:node-exporter和Prometheus的版本更新非常频繁,建议在部署前查阅最新文档。
    • 依赖关系:确保Prometheus和Node-Exporter的版本是兼容的。

    4. 端口暴露

    为了方便测试和访问,可以将Prometheus或Node-Exporter的服务端口暴露到外部。

    方法一:使用Minikube Tunnel

    如果使用Minikube或其他Kubernetes集群,可以通过以下命令暴露服务:

    kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') 9090:9090 &

    方法二:端口转发

    对于本地开发,可以使用端口转发:

    kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') 9090:9090 &

    这样,你就可以通过localhost:9090或指定IP地址访问Prometheus服务了。

    上一篇:Java 异常
    下一篇:Java Arrays

    发表评论

    最新留言

    网站不错 人气很旺了 加油
    [***.192.178.218]2025年04月06日 03时30分24秒