Kubernetes 使用普罗米修斯吊舱监控golang webapp吊舱
我有一个golang webapp吊舱在kubernetes集群中运行,我试图部署一个prometheus吊舱来监控golang webapp吊舱 我在service.yaml文件中指定了Kubernetes 使用普罗米修斯吊舱监控golang webapp吊舱,kubernetes,prometheus,Kubernetes,Prometheus,我有一个golang webapp吊舱在kubernetes集群中运行,我试图部署一个prometheus吊舱来监控golang webapp吊舱 我在service.yaml文件中指定了prometheus.io/port:to 2112,这是golang webapp正在侦听的端口,但当我转到prometheus仪表板时,它显示2112端点已关闭 我正在跟踪,尝试了这个线程的解决方案,但仍然得到结果说2112端点已关闭 下面是my service.yaml和deployment.yaml a
prometheus.io/port:to 2112
,这是golang webapp正在侦听的端口,但当我转到prometheus仪表板时,它显示2112
端点已关闭
我正在跟踪,尝试了这个线程的解决方案,但仍然得到结果说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部署部分添加
prometheus.io/port:2112
,因为我怀疑这可能是原因。我对注释的放置位置感到困惑,因此得到了澄清,我需要将其放在服务的元数据下,需要prothemeus对其进行清理。所以在我的例子中,它需要在goapp的元数据中
apiVersion: v1
kind: Service
metadata:
namespace: monitoring
name: goapp
annotations:
prometheus.io/scrape: 'true'
prometheus.io/path: '/metrics'
prometheus.io/port: '2112'
你确定你的goapp像普罗米修斯期望的那样公开了它的指标吗?当您在
:2112/metrics
处查询应用程序时会发生什么情况?@YaronIdan当我在/metrics处查询golang应用程序时,它会显示度量。我想我不知道应该把注释放在哪里,它看起来需要放在golang应用程序部分,我试图把它放在golang应用程序的元数据下,但pod似乎没有出现在Prometheus仪表板中。