Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Kubernetes集群中使用Python设置Prometheus_Python_Kubernetes_Prometheus_Azure Aks - Fatal编程技术网

在Kubernetes集群中使用Python设置Prometheus

在Kubernetes集群中使用Python设置Prometheus,python,kubernetes,prometheus,azure-aks,Python,Kubernetes,Prometheus,Azure Aks,我正在将普罗米修斯与我下载的舵手图整合到库伯内特斯星系群中。如果你必须知道的话,我正在使用Azure部署我的AKS。在我的每个pod中,容器运行一个Docker映像,其中包括控制我的主pod中的工作流的master_server.py脚本 我正试图通过官方的Prometheus Python包通过master_server.py从我的主吊舱中获取一些自定义指标。我的master_server.py看起来像这样 . . . containers: - name: master-pod-name

我正在将普罗米修斯与我下载的舵手图整合到库伯内特斯星系群中。如果你必须知道的话,我正在使用Azure部署我的AKS。在我的每个pod中,容器运行一个Docker映像,其中包括控制我的主pod中的工作流的
master_server.py
脚本

我正试图通过官方的Prometheus Python包通过
master_server.py
从我的主吊舱中获取一些自定义指标。我的
master_server.py
看起来像这样

.
.
.
containers:
  - name: master-pod-name
    image: master-pod-image
    ports:
      - name: http
        containerPort: 8080 # this is for my Tornado web server
        protocol: TCP
      - name: prometheus
        containerPort: 8081
.
.
.
master_server.py
(截断)

我在谷歌上搜索了一个lil,发现我需要添加注释,以便普罗米修斯能够从我的主吊舱中获取数据。因此,在我的
deployment.yaml
文件中,我添加了以下代码片段,以允许普罗米修斯从我的主吊舱中刮取数据

  template:
    metadata:
      annotations:
        prometheus.io/scrape: 'true'
        prometheus.io/port: '8081'
Name:                   kaldi-feature-test-master
Namespace:              kaldi-test
CreationTimestamp:      Fri, 10 Jan 2020 01:53:09 +0800
Labels:                 app.kubernetes.io/instance=kaldi-feature-test
                        app.kubernetes.io/managed-by=Tiller
                        app.kubernetes.io/name=kaldi-feature-test-master
                        helm.sh/chart=kaldi-feature-test-0.1.0
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app.kubernetes.io/instance=kaldi-feature-test,app.kubernetes.io/name=kaldi-feature-test-master
Replicas:               2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:       app.kubernetes.io/instance=kaldi-feature-test
                app.kubernetes.io/name=kaldi-feature-test-master
  Annotations:  prometheus.io/port: 8081
                prometheus.io/scrape: true
  Containers:
   kaldi-feature-test-master:
    Image:      kalditest.azurecr.io/kalditestscaled:latest
    Port:       8080/TCP
    Host Port:  0/TCP
    Command:
      /home/appuser/opt/tini
      --
      /home/appuser/opt/start_master.sh
    Limits:
      cpu:     2
      memory:  2Gi
    Requests:
      cpu:      2
      memory:   2Gi
    Liveness:   http-get http://:http/ delay=0s timeout=1s period=10s #success=1 #failure=3
    Readiness:  http-get http://:http/ delay=0s timeout=1s period=10s #success=1 #failure=3
    Environment Variables from:
      environment-variables-master-secret  Secret  Optional: false
    Environment:                           <none>
    Mounts:                                <none>
  Volumes:                                 <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   kaldi-feature-test-master-79886c5d76 (2/2 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  15m   deployment-controller  Scaled up replica set kaldi-feature-test-master-79886c5d76 to 2
不过,它还是不起作用。我无法在Prometheus查询中看到我的自定义指标

以下是主吊舱的my
部署.yaml

  template:
    metadata:
      annotations:
        prometheus.io/scrape: 'true'
        prometheus.io/port: '8081'
Name:                   kaldi-feature-test-master
Namespace:              kaldi-test
CreationTimestamp:      Fri, 10 Jan 2020 01:53:09 +0800
Labels:                 app.kubernetes.io/instance=kaldi-feature-test
                        app.kubernetes.io/managed-by=Tiller
                        app.kubernetes.io/name=kaldi-feature-test-master
                        helm.sh/chart=kaldi-feature-test-0.1.0
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app.kubernetes.io/instance=kaldi-feature-test,app.kubernetes.io/name=kaldi-feature-test-master
Replicas:               2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:       app.kubernetes.io/instance=kaldi-feature-test
                app.kubernetes.io/name=kaldi-feature-test-master
  Annotations:  prometheus.io/port: 8081
                prometheus.io/scrape: true
  Containers:
   kaldi-feature-test-master:
    Image:      kalditest.azurecr.io/kalditestscaled:latest
    Port:       8080/TCP
    Host Port:  0/TCP
    Command:
      /home/appuser/opt/tini
      --
      /home/appuser/opt/start_master.sh
    Limits:
      cpu:     2
      memory:  2Gi
    Requests:
      cpu:      2
      memory:   2Gi
    Liveness:   http-get http://:http/ delay=0s timeout=1s period=10s #success=1 #failure=3
    Readiness:  http-get http://:http/ delay=0s timeout=1s period=10s #success=1 #failure=3
    Environment Variables from:
      environment-variables-master-secret  Secret  Optional: false
    Environment:                           <none>
    Mounts:                                <none>
  Volumes:                                 <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   kaldi-feature-test-master-79886c5d76 (2/2 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  15m   deployment-controller  Scaled up replica set kaldi-feature-test-master-79886c5d76 to 2
名称:kaldi功能测试主机
名称空间:kaldi测试
CreationTimestamp:Fri,2020年1月10日01:53:09+0800
标签:app.kubernetes.io/instance=kaldi特性测试
app.kubernetes.io/managed by=Tiller
app.kubernetes.io/name=kaldi特性测试主机
舵手sh/chart=kaldi-feature-test-0.1.0
注释:deployment.kubernetes.io/revision:1
选择器:app.kubernetes.io/instance=kaldi feature test,app.kubernetes.io/name=kaldi feature test master
副本:需要2份|更新2份|共2份|可用2份|不可用0份
策略类型:RollingUpdate
最小就绪秒:0
滚动更新策略:最多25%不可用,最多25%喘振
Pod模板:
标签:app.kubernetes.io/instance=kaldi特性测试
app.kubernetes.io/name=kaldi特性测试主机
注释:prometheus.io/port:8081
普罗米修斯:对
容器:
kaldi特性测试主机:
图片:kalditest.azurecr.io/kalditest缩放:最新
端口:8080/TCP
主机端口:0/TCP
命令:
/主页/appuser/opt/tini
--
/home/appuser/opt/start\u master.sh
限制:
中央处理器:2
内存:2Gi
请求:
中央处理器:2
内存:2Gi
活跃度:http get http://:http/delay=0s超时=1s周期=10s成功=1失败=3
准备就绪:http get http://:http/delay=0s超时=1s周期=10s成功=1失败=3
环境变量来自:
环境变量主密钥机密可选:false
环境:
挂载:
卷数:
条件:
类型状态原因
----           ------  ------
可用真最小值ReplicasAvailable
正在进行的True NewReplicateSetAvailable
旧复制集:
NewReplicaSet:kaldi-feature-test-master-79886c5d76(创建了2/2个副本)
活动:
从消息中键入原因年龄
----    ------             ----  ----                   -------
正常扩展复制集15m部署控制器扩展复制集kaldi-feature-test-master-79886c5d76至2
我检查了普罗米修斯的目标,意识到我的主吊舱被拒绝连接。


我该怎么做才能让普罗米修斯从我的主吊舱中刮取自定义指标呢?

是的,多亏了查尔斯的评论,我才得以工作

我在端口8080的主吊舱中为我的应用程序运行了一个测试,这样可能会中断Prometheus HTTP服务器,从而从主吊舱中获取度量

最后,我在主吊舱的
部署中在8081打开了另一个端口

.
.
.
containers:
  - name: master-pod-name
    image: master-pod-image
    ports:
      - name: http
        containerPort: 8080 # this is for my Tornado web server
        protocol: TCP
      - name: prometheus
        containerPort: 8081
.
.
.

然后在主吊舱中运行的python脚本中,我将Prometheus服务器设置为在端口8081处运行。最后它成功了-
prom.start\u http\u server(8081)

从您提供的Python代码和部署YAML文件可以看出,http服务器侦听端口8081,但您只公开了端口8080,不包括端口8081


因此,解决方案是,您需要在部署的容器
kaldi feature test master
和将请求路由到部署的应用程序的服务中公开端口8081。

看起来python客户端没有正常运行。尝试转发并直接发送请求:kubectl port forward name_of_pod 8081:8081,然后在浏览器中访问。通过这种方式,您可以直接访问以查看它是否工作,因此您可以调试所使用的python客户机。它应该显示一个带有一些数字的网页,在您的情况下可能会说连接被拒绝。是的,我转发了端口,但本地主机仍拒绝连接:8081我们需要更多详细信息来帮助您。能否以YAML的形式提供您的配置?或者我们可以使用的任何其他信息/配置?为我的主播客添加了
deployment.yaml
,因为我看到您只公开端口8080,并且希望使用端口8081访问以获取度量。你怎么做?我想你最好让我加上答案并接受它,而不是自己加上。这是礼貌。当然,我会把你的答案记为正确答案:)