我在kubernetes集群中运行了一个golang webapp pod,并且我尝试部署一个prometheus pod来监控golang webapp pod。
我在service.yaml文件中指定了prometheus.io/port: to 2112,这是golang when应用程序正在侦听的端口,但是当我转到Prometheus仪表板时,它显示2112端点已关闭。
我正在关注this guide,尝试了这个线程的解决方案thread,但仍然得到2112端点关闭的结果。
下面是my service.yaml和deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: prometheus-service
namespace: monitoring
annotations:
prometheus.io/scrape: 'true'
prometheus.io/path: '/metrics'
prometheus.io/port: '2112'
spec:
selector:
app: prometheus-server
type: NodePort
ports:
- port: 8080
targetPort: 9090
nodePort: 30000
---
apiVersion: v1
kind: Service
metadata:
namespace: monitoring
name: goapp
spec:
type: NodePort
selector:
app: golang
ports:
- name: main
protocol: TCP
port: 80
targetPort: 2112
nodePort: 30001
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus-deployment
namespace: monitoring
labels:
app: prometheus-server
spec:
replicas: 1
selector:
matchLabels:
app: prometheus-server
template:
metadata:
labels:
app: prometheus-server
spec:
containers:
- name: prometheus
image: prom/prometheus
args:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus/"
ports:
- containerPort: 9090
volumeMounts:
- name: prometheus-config-volume
mountPath: /etc/prometheus/
- name: prometheus-storage-volume
mountPath: /prometheus/
volumes:
- name: prometheus-config-volume
configMap:
defaultMode: 420
name: prometheus-server-conf
- name: prometheus-storage-volume
emptyDir: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: monitoring
name: golang
spec:
replicas: 1
template:
metadata:
labels:
app: golang
spec:
containers:
- name: gogo
image: effy77/gogo2
ports:
- containerPort: 2112
selector:
matchLabels:
app: golang我将尝试将prometheus.io/port: 2112添加到prometheus部署部分,因为我怀疑这可能是原因。
发布于 2021-01-31 00:37:16
我不知道把注解放在哪里,从这个thread中得到了澄清,我需要把它放在服务的元数据下,而这些元数据需要被prothemeus抓取。因此,在我的例子中,它需要在goapp的元数据中。
apiVersion: v1
kind: Service
metadata:
namespace: monitoring
name: goapp
annotations:
prometheus.io/scrape: 'true'
prometheus.io/path: '/metrics'
prometheus.io/port: '2112'https://stackoverflow.com/questions/65969773
复制相似问题