首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用prometheus pod监视golang webapp pod

使用prometheus pod监视golang webapp pod
EN

Stack Overflow用户
提问于 2021-01-30 23:31:28
回答 1查看 56关注 0票数 1

我在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

代码语言:javascript
复制
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部署部分,因为我怀疑这可能是原因。

EN

回答 1

Stack Overflow用户

发布于 2021-01-31 00:37:16

我不知道把注解放在哪里,从这个thread中得到了澄清,我需要把它放在服务的元数据下,而这些元数据需要被prothemeus抓取。因此,在我的例子中,它需要在goapp的元数据中。

代码语言:javascript
复制
apiVersion: v1
kind: Service
metadata: 
  namespace: monitoring
  name: goapp
  annotations:
      prometheus.io/scrape: 'true'
      prometheus.io/path: '/metrics'
      prometheus.io/port:   '2112'
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65969773

复制
相关文章

相似问题

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