prometheus operator - 启用对所有命名空间中的所有内容的监控 [英] prometheus operator - enable monitoring for everything in all namespaces
问题描述
我想通过 prometheus-operator 监控在名为 development
和 production
的命名空间中的 Kubernetes 集群上运行的几个应用程序.
I want to monitor a couple applications running on a Kubernetes cluster in namespaces named development
and production
through prometheus-operator.
使用的安装命令(根据 Github)是:
Installation command used (as per Github) is:
helm install prometheus-operator stable/prometheus-operator -n production --set prometheusOperator.enabled=true,prometheus.service.type=NodePort,prometheusOperator.service.type=NodePort,alertmanager.service.type=NodePort,grafana.service.type=NodePort,grafana.service.nodePort=30906
我需要向上述命令添加哪些参数才能让 prometheus-operator
发现和监控在所有 命名空间
中运行的所有应用程序/服务/Pod?
What parameters do I need to add to above command to have prometheus-operator
discover and monitor all apps/services/pods running in all namespaces
?
有了这个,Service Discovery
只显示一些 prometheus-operator
相关的 services
,而不是我在生产"中运行的应用程序即使 prometheus-operator
安装在同一个 namespace
中.
With this, Service Discovery
only shows some prometheus-operator
related services
, but not the app that I am running within 'production' namespace even though prometheus-operator
is installed in the same namespace
.
有什么我遗漏的吗?
注意 - 正在使用同一用户(使用 $HOME/.kube/config 文件
)执行所有操作,所以我认为权限不是问题.
Note - Am running performing all actions using the same user (which uses the $HOME/.kube/config file
), so I assume permissions are not an issue.
kubectl 版本 - v1.17.3掌舵版本 - 3.1.2
kubectl version - v1.17.3 helm version - 3.1.2
附言在不同的论坛上有很多关于此的文章,但我仍然没有找到简单而直接的答案.
P.S. There are numerous articles on this on different forums, but am still not finding simple and direct answers for this.
推荐答案
我遇到了同样的问题.经过一些调查回答更多细节.
I had the same problem. After some investigation answering with more details.
我已经通过 Helm charts 安装了 Prometheus 堆栈,其中直接包含 Prometheus 运算符图表作为一个子项目.Prometheus operator 监视由以下 helm 值指定的命名空间:
I've installed Prometheus stack via Helm charts which include Prometheus operator chart directly as a sub-project. Prometheus operator monitors namespaces specified by the following helm values:
prometheusOperator:
namespaces: ''
denyNamespaces: ''
prometheusInstanceNamespaces: ''
alertmanagerInstanceNamespaces: ''
thanosRulerInstanceNamespaces: ''
namespaces
值指定 ServiceMonitor 和 PodMonitor CRD 的受监控命名空间.其他 CRD 有自己的设置,如果没有设置,默认为 namespaces
.Helm 值作为命令行参数传递给运算符.请参见 这里 和这里.
The namespaces
value specifies monitored namespaces for ServiceMonitor and PodMonitor CRDs. Other CRDs have their own settings, which if not set, default to namespaces
. Helm values are passed as command-line arguments to the operator. See here and here.
Prometheus CRD 由操作员从提到的命名空间中选取,默认情况下 - 无处不在.但是,由于 Operator 的设计考虑到了多个 Prometheus 的同时发布,因此特定 Prometheus 应用程序实例选择的内容由相应的 Prometheus CRD 控制.CRD 选择器和相应的命名空间选择器通过以下 Helm 值控制:
Prometheus CRDs are picked up by the operator from the mentioned namespaces, by default - everywhere. However, as the operator is designed with multiple simultaneous Prometheus releases in mind, what to pick up by a particular Prometheus app instance is controlled by the corresponding Prometheus CRD. CRDs selectors and corresponding namespaces selectors are controlled via the following Helm values:
prometheus:
prometheusSpec:
serviceMonitorSelectorNilUsesHelmValues: true
serviceMonitorSelector: {}
serviceMonitorNamespaceSelector: {}
其他 CRD 也有类似的值:alertmanagerConfigXXX、ruleNamespaceXXX、podMonitorXXX、probeXXX.XXXSelectorNilUsesHelmValues
设置为 true,表示查找具有特定发布标签的 CRD,例如release=myrelease
.请参阅prometheus.yaml#这里.
Similar values are present for other CRDs: alertmanagerConfigXXX, ruleNamespaceXXX, podMonitorXXX, probeXXX. XXXSelectorNilUsesHelmValues
set to true, means to look for CRD with particular release label, e.g. release=myrelease
. See here.
空选择器(用于命名空间、CRD 或任何其他对象)意味着没有过滤.因此,对于 Prometheus 对象从其他命名空间中获取 ServiceMonitor 的选择很少:
Empty selector (for a namespace, CRD, or any other object) means no filtering. So for Prometheus object to pick up a ServiceMonitor from the other namespaces there are few options:
- 设置
serviceMonitorSelectorNilUsesHelmValues: false
.这使得 serviceMonitorSelector 为空. - 应用发布标签,例如
release=myrelease
,发送到您的 ServiceMonitor CRD. - 设置一个与您的 ServiceMonitor 匹配的非空 serviceMonitorSelector.
- Set
serviceMonitorSelectorNilUsesHelmValues: false
. This leaves serviceMonitorSelector empty. - Apply the release label, e.g.
release=myrelease
, to your ServiceMonitor CRD. - Set a non-empty serviceMonitorSelector that matches your ServiceMonitor.
对于好奇的人,这里是运营商来源的链接:
For the curious ones here are links to the operator sources:
这篇关于prometheus operator - 启用对所有命名空间中的所有内容的监控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!