首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nginx-prometheus-exporter部署失败

nginx-prometheus-exporter部署失败
EN

Stack Overflow用户
提问于 2019-05-15 04:04:46
回答 1查看 1.6K关注 0票数 1

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

代码语言:javascript
复制
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 sidecar容器时失败。

代码语言:javascript
复制
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容器

代码语言:javascript
复制
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:/#
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-15 04:27:44

nginx容器监听80端口,您配置sidecar访问8080端口。此外,您将其部署在"production“名称空间中,但使用"test”访问nginx。

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

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

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56137852

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档