关于k8s中的node_exporter异常write: broken pipe问题排查

公司网络更改重启服务器后,发现Prometheus监控中node节点三个挂掉了,实际上节点服务器是正常的,但是监控的node_exporter请求http://IP:9100/metrics超过10秒没有获取返回数据则认为服务挂掉。

到各个节点服务器用curl命令检测多久返回数据

curl -o /dev/null -s -w '%{time_connect}:%{time_starttransfer}:%{time_total}\n' 'http://NodeIP:9100/metrics'
time_connect :连接时间,从开始到TCP三次握手完成时间,这里面包括DNS解析的时候,如果想求连接时间,需要减去上面的解析时间;
time_starttransfer :开始传输时间,从发起请求开始,到服务器返回第一个字段的时间;
time_total :总时间;
可以看到time_connect时间是很快的,排除网络问题。除了167返回时间正常其他几个节点都是有问题的。

查看pod日志

ts=2023-01-11T06:11:08.189Z caller=stdlib.go:105 level=error caller="error encoding and sending metric family: write tcp 163:9100" msg="-> 167:40743: write: broken pipe"
ts=2023-01-11T06:11:08.189Z caller=stdlib.go:105 level=error caller="error encoding and sending metric family: write tcp 163:9100" msg="->.167:40743: write: broken pipe"

可以看到有大量的这种日志

参考资料: https://asktug.com/t/topic/153284/36https://blog.csdn.net/lyf0327/article/details/99971590

有些说可以调大scrape_timeout这个时间,但是这个不是解决问题的根本

也有说调大node_exporter的yaml中的limit内存和CPU,但是我这边的node_exporter是没有配置request和limit资源的,也不是这个问题,最后参考别人的配置文件

apiVersion: apps/v1
kind: DaemonSet
metadata:
  annotations:
    deprecated.daemonset.template.generation: "5"
    prometheus.io/scrape: "true"
  generation: 5
  labels:
    app: node-exporter
  name: node-exporter
  namespace: monitoring
spec:
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: node-exporter
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: node-exporter
      name: node-exporter
    spec:
      containers:
      - args:
        - --web.listen-address=$(HOSTIP):9100
        - --path.procfs=/host/proc
        - --path.sysfs=/host/sys
        - --path.rootfs=/host   # 修改了这个原来是/host/root
        - --collector.filesystem.ignored-mount-points=^/(dev|proc|sys|var/lib/docker/.+)($|/)
        - --collector.filesystem.ignored-fs-types=^(autofs|binfmt_misc|cgroup|configfs|debugfs|devpts|devtmpfs|fusectl|hugetlbfs|mqueue|overlay|proc|procfs|pstore|rpc_pipefs|securityfs|sysfs|tracefs)$
        - --log.level=debug
        env:
        - name: HOSTIP
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: status.hostIP
        image: prom/node-exporter:latest
        imagePullPolicy: IfNotPresent
        name: node-exporter
        ports:
        - containerPort: 9100
          hostPort: 9100
          protocol: TCP
        resources: {}
        securityContext:
          privileged: true
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /host/proc
          name: proc
        - mountPath: /host/sys
          name: sys
        - mountPath: /host     # 修改了这个原来是/rootfs
          name: rootfs
      dnsPolicy: ClusterFirst
      hostIPC: true
      hostNetwork: true
      hostPID: true
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      tolerations:
      - effect: NoSchedule
        key: node-role.kubernetes.io/master
        operator: Exists
      volumes:
      - hostPath:
          path: /proc
        name: proc
      - hostPath:
          path: /sys
        name: sys
      - hostPath:
          path: /    
        name: rootfs
  updateStrategy:
    rollingUpdate:
      maxSurge: 0
      maxUnavailable: 1
    type: RollingUpdate

观察了一天

根据上述修改后仍有问题,其中一个报权限不足

apiVersion: apps/v1
kind: DaemonSet
metadata:
  annotations:
    deprecated.daemonset.template.generation: "5"
    prometheus.io/scrape: "true"
  generation: 5
  labels:
    app: node-exporter
  name: node-exporter
  namespace: monitoring
spec:
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: node-exporter
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: node-exporter
      name: node-exporter
    spec:
      containers:
      - args:
        - --web.listen-address=$(HOSTIP):9100
        - --path.procfs=/host/proc
        - --path.sysfs=/host/sys
        - --path.rootfs=/host
        - --collector.filesystem.ignored-mount-points=^/(dev|proc|sys|var/lib/docker/.+)($|/)
        - --collector.filesystem.ignored-fs-types=^(autofs|binfmt_misc|cgroup|configfs|debugfs|devpts|devtmpfs|fusectl|hugetlbfs|mqueue|overlay|proc|procfs|pstore|rpc_pipefs|securityfs|sysfs|tracefs)$
        - --log.level=debug
        env:
        - name: HOSTIP
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: status.hostIP
        image: prom/node-exporter:latest
        imagePullPolicy: IfNotPresent
        name: node-exporter
        ports:
        - containerPort: 9100
          hostPort: 9100
          protocol: TCP
        resources: {}
        securityContext:
          privileged: true
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /host/proc
          name: proc
        - mountPath: /host/sys
          name: sys
        - mountPath: /host
          name: rootfs
      dnsPolicy: ClusterFirst
      hostIPC: true
      hostNetwork: true
      hostPID: true
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: 
        runAsUser: 0   # 添加该选项 默认是nobody用户 65534的uid
      terminationGracePeriodSeconds: 30
      tolerations:
      - effect: NoSchedule
        key: node-role.kubernetes.io/master
        operator: Exists
      volumes:
      - hostPath:
          path: /proc
        name: proc
      - hostPath:
          path: /sys
        name: sys
      - hostPath:
          path: /
        name: rootfs
  updateStrategy:
    rollingUpdate:
      maxSurge: 0
      maxUnavailable: 1
    type: RollingUpdate

再观察一天最新的问题有重新出现

报大量的error encoding and sending metric family: write tcp 10.37.0.163:9100" msg="->10.37.0.167:50266: write: broken pip

查了很多资料最后一个资料比较有用

地址:https://github.com/prometheus/node_exporter/issues/2500

我这边的节点3个内核是5.4.0-132,三个都是有问题的,而更高版本的内核5.15.0是没问题的
最终结论是内核版本问题;
临时解决方案是在node_exporter中添加环境变量GOMAXPROCS=1
永久解决是升级内核
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!要在Kubernetes上部署snmp_exporter,您可以按照以下步骤进行操作: 1. 首先,创建一个部署文件(deployment.yaml),内容如下: ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: snmp-exporter spec: replicas: 1 selector: matchLabels: app: snmp-exporter template: metadata: labels: app: snmp-exporter spec: containers: - name: snmp-exporter image: prom/snmp-exporter ports: - containerPort: 9116 args: - "--config.file=/etc/snmp_exporter/snmp.yml" volumeMounts: - name: config-volume mountPath: /etc/snmp_exporter volumes: - name: config-volume configMap: name: snmp-config ``` 2. 创建一个配置文件(configmap.yaml),内容如下: ```yaml apiVersion: v1 kind: ConfigMap metadata: name: snmp-config data: snmp.yml: | version: 2c communities: - community_string: public target_oids: - .1.3.6.1.2.1.2.2.1.10 ``` 此配置文件示例设置了SNMP版本为2c,使用公共社区字符串(public)并监视了接口的入站字节数。您可以根据需要进行修改。 3. 使用kubectl命令进行部署: ```shell kubectl apply -f deployment.yaml kubectl apply -f configmap.yaml ``` 这将创建一个名为"snmp-exporter"的部署,并创建一个名为"snmp-config"的配置映射。 4. 部署完成后,您可以通过访问snmp-exporter服务的IP地址和端口(默认为9116)来访问snmp_exporter的指标数据。 ```shell kubectl get services ``` 您应该能够看到"snmp-exporter"服务的外部IP地址。使用该IP地址和端口号,您可以使用Prometheus或其他监控工具来获取和可视化snmp_exporter的指标数据。 希望这对您有所帮助!如有任何问题,请随时问我。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值