gpt4 book ai didi

nginx - nginx-prometheus-exporter部署失败

转载 作者:行者123 更新时间:2023-12-02 12:04:15 26 4
gpt4 key购买 nike

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

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

单个容器容器可以工作,但是当我添加 nginx-prometheus-exporter sidecar容器时失败。
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)

还能够从另一个在不同 namespace 中运行的容器中 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:/#

最佳答案

nginx容器正在侦听端口80,并且您将Sidecar配置为访问8080端口。此外,您可以在“生产” namespace 中部署它,但是使用“测试”来访问nginx。

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

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

因此,您可以使用-nginx.scrape-uri=http://localhost/stub_status

关于nginx - nginx-prometheus-exporter部署失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56137852/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com