Prometheus Operator

Prometheus Operator

简介

Prometheus Operator 提供 Kubernetes 原生部署和管理 Prometheus 和相关监控组件。该项目的目的是简化和自动化基于 Prometheus 的 Kubernetes 集群监控堆栈的配置。

安装

拉取项目:

1
2
git clone https://github.com/prometheus-operator/kube-prometheus.git
cd kube-prometheus

初始化基本环境:

1
2
kubectl create -f manifests/setup
until kubectl get servicemonitors --all-namespaces ; do date; sleep 1; echo ""; done

注:若输出为 No resources found 则代表可执行下一步。

拉取镜像并修改容器地址:

  • prometheusAdapter-deployment.yaml
  • kubeStateMetrics-deployment.yaml
1
2
registry.k8s.io/prometheus-adapter/prometheus-adapter:{version}
registry.k8s.io/kube-state-metrics/kube-state-metrics:{version}

部署服务:

1
kubectl create -f manifests/

编写 prometheus.yaml 并部署 Ingress :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
name: grafana-ingress
namespace: monitoring
spec:
ingressClassName: nginx
rules:
- host: grafana.<host>
http:
paths:
- backend:
service:
name: grafana
port:
number: 3000
path: /
pathType: Prefix
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
name: alertmanager-ingress
namespace: monitoring
spec:
ingressClassName: nginx
rules:
- host: alert.<host>
http:
paths:
- backend:
service:
name: alertmanager-main
port:
number: 9093
path: /
pathType: Prefix
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
name: prometheus-ingress
namespace: monitoring
spec:
ingressClassName: nginx
rules:
- host: prometheus.<host>
http:
paths:
- backend:
service:
name: prometheus-k8s
port:
number: 9090
path: /
pathType: Prefix
1
kubectl apply -f prometheus.yaml

参考资料

官方文档


Prometheus Operator
https://wangqian0306.github.io/2023/prometheus-operator/
作者
WangQian
发布于
2023年1月16日
许可协议