【问题标题】:nginx-prometheus-exporter deployment failingnginx-prometheus-exporter 部署失败
【发布时间】:2019-10-01 22:04:13
【问题描述】:

我正在尝试使用nginx-prometheus-exporter 部署Nginx。以下是我的部署

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  namespace: local
  name: nginx
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        imagePullPolicy: Always
        ports:
        - name: nginx-port
          containerPort: 80
          protocol: TCP
        livenessProbe:
          httpGet:
            path: /
            port: nginx-port
            httpHeaders:
              - name: Host
                value: KubernetesLivenessProbe
          initialDelaySeconds: 10
          timeoutSeconds: 1
          periodSeconds: 15
        readinessProbe:
          httpGet:
            path: /
            port: nginx-port
            httpHeaders:
              - name: Host
                value: KubernetesLivenessProbe
          initialDelaySeconds: 3
          timeoutSeconds: 1
          periodSeconds: 8
        volumeMounts:
        - mountPath: /etc/nginx/conf.d/ # mount nginx-conf volume to /etc/nginx
          readOnly: true
          name: frontend-conf
      - name: nginx-exporter
        image: nginx/nginx-prometheus-exporter:0.3.0
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - name: nginx-ex-port
          containerPort: 9113
        args:
          - -nginx.scrape-uri=http://nginx.local.svc.cluster.local:80/stub_status
      volumes:
      - name: frontend-conf
        configMap:
          name: frontend-conf # place ConfigMap `nginx-conf` on /etc/nginx
          items:
            - key: frontend.local.conf
              path: frontend.local.conf 

单个容器 pod 可以工作,但是当我添加 nginx-prometheus-exporter 边车容器时失败。

mackbook: xyz$ kubectl logs nginx-6dbbdb64fb-8drmc -c nginx-exporter
2019/05/14 20:17:48 Starting NGINX Prometheus Exporter Version=0.3.0 GitCommit=6570275
2019/05/14 20:17:53 Could not create Nginx Client: Failed to create NginxClient: failed to get http://nginx.local.svc.cluster.local:80/stub_status: Get http://nginx.local.svc.cluster.local:80/stub_status: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

还能够从另一个运行在不同命名空间中的容器curl http://nginx.local.svc.cluster.local

有人知道指定 -nginx.scrape-uri 的正确方法是什么吗?

来自 Nginx 容器

root@nginx-6fd866c4d7-t8wwf:/# curl localhost/stub_status
<html>
<head><title>404 Not Found</title></head>
<body>
<h1>404 Not Found</h1>
<ul>
<li>Code: NoSuchKey</li>
<li>Message: The specified key does not exist.</li>
<li>Key: beta/stub_status</li>
<li>RequestId: 3319E5A424C7BA31</li>
<li>HostId: zVv5zuAyzqbB2Gw3w1DavEJwgq2sbgI8RPMf7RmPsNQoh/9ftxCmiSwyj/j6q/K3lxEEeUy6aZM=</li>
</ul>
<hr/>
</body>
</html>
root@nginx-6fd866c4d7-t8wwf:/#

【问题讨论】:

  • “失败”是什么意思?你能告诉我们边车日志吗?
  • 从 sidecar 容器中添加了日志。

标签: nginx kubernetes prometheus prometheus-node-exporter prometheus-blackbox-exporter


【解决方案1】:

nginx 容器正在监听 80 端口,您将 sidecar 配置为访问 8080 端口。此外,您将其部署在“生产”命名空间中,但使用“测试”来访问 nginx。

试试-nginx.scrape-uri=http://nginx.production.svc.cluster.local:80/stub_status

顺便说一句,您必须知道 Pod 中的容器共享一个 IP 地址和端口空间,并且可以通过 localhost 找到彼此。

所以你可以使用-nginx.scrape-uri=http://localhost/stub_status

【讨论】:

  • 仍然无法使用 localhost 吗?在这种情况下,sidecar 日志是否更改?你能用 bash 进入 nginx 容器并在 localhost/stub_status 上做一个 curl 吗?卷曲的结果是什么?
  • 所以我认为使用 localhost,sidecar 现在可以到达 nginx 容器(您可以尝试进入 sidecar 容器并在 localhost/stub_status 上执行 curl - 您也应该有 404)。这里的重点是 nginx 没有暴露 stub_status。你能告诉我们frontend.local.conf的内容吗?
  • 完全忘记在 nginx 配置中添加 location /stub_status {stub_status;}
  • 我需要在 static_configs - targets: ['nginx.local.svc.cluster.local:80'] 中使用什么目标?
  • 使用边车端口,即 9113
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-12
  • 2020-06-18
  • 1970-01-01
  • 2016-03-16
  • 2020-02-13
  • 2023-02-09
  • 2019-06-01
相关资源
最近更新 更多