在 Prometheus Operator 中创建 ServiceMonitor
Create ServiceMonitor in Prometheus Operator
我是 Kubernetes 新手。我想在 Prometheus Operator 中创建服务监视器。我已经安装了 Prometheus Operator 和 Grafana。我有 运行ning pods 如下所示:
documentation of Prometheus Operator 提供了以下代码来创建服务监视器。
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: prometheus
spec:
serviceAccountName: prometheus
serviceMonitorSelector:
matchLabels:
team: frontend
resources:
requests:
memory: 400Mi
enableAdminAPI: false
我知道这是一个 yaml 文件,但我很困惑如何 运行 这个文件?也就是说,我应该把这段代码放到哪里呢?我正在学习创建 Prometheus 监视器。我能得到一些帮助吗?
谢谢!
您可以像 Kubernetes 集群中的任何其他清单一样部署它,例如 运行 kubectl apply -f servicemonitor.yaml
。
您可以通过 运行 kubectl get prometheus
:
检查它是否已部署
$ kubectl get prometheus
NAME VERSION REPLICAS AGE
prometheus 5s
当您启用 RBAC 授权时,您应该使用另一个 yaml:
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: prometheus
labels:
prometheus: prometheus
spec:
replicas: 2
serviceAccountName: prometheus
serviceMonitorSelector:
matchLabels:
team: frontend
alerting:
alertmanagers:
- namespace: default
name: alertmanager
port: web
我是 Kubernetes 新手。我想在 Prometheus Operator 中创建服务监视器。我已经安装了 Prometheus Operator 和 Grafana。我有 运行ning pods 如下所示:
documentation of Prometheus Operator 提供了以下代码来创建服务监视器。
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: prometheus
spec:
serviceAccountName: prometheus
serviceMonitorSelector:
matchLabels:
team: frontend
resources:
requests:
memory: 400Mi
enableAdminAPI: false
我知道这是一个 yaml 文件,但我很困惑如何 运行 这个文件?也就是说,我应该把这段代码放到哪里呢?我正在学习创建 Prometheus 监视器。我能得到一些帮助吗?
谢谢!
您可以像 Kubernetes 集群中的任何其他清单一样部署它,例如 运行 kubectl apply -f servicemonitor.yaml
。
您可以通过 运行 kubectl get prometheus
:
$ kubectl get prometheus
NAME VERSION REPLICAS AGE
prometheus 5s
当您启用 RBAC 授权时,您应该使用另一个 yaml:
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: prometheus
labels:
prometheus: prometheus
spec:
replicas: 2
serviceAccountName: prometheus
serviceMonitorSelector:
matchLabels:
team: frontend
alerting:
alertmanagers:
- namespace: default
name: alertmanager
port: web