Prometheus Operator配置Consul服务自动发现
1、在monitoring名称空间部署consul服务,consul.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: consul
namespace: monitoring
labels:
app: consul
spec:
selector:
matchLabels:
app: consul
replicas: 1
template:
metadata:
name: consul
labels:
app: consul
spec:
containers:
- name: consul
image: consul:latest
ports:
- containerPort: 8500
protocol: TCP
imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
name: consul
namespace: monitoring
labels:
app: consul
spec:
selector:
app: consul
ports:
- name: consul
protocol: TCP
port: 8500
targetPort: 8500
2、编写prometheus-additional配置,prometheus-additional.yaml
- job_name: consul
consul_sd_configs:
- server: consul.monitoring.svc:8500
relabel_configs:
- source_labels: [__meta_consul_tags]
regex: .*,prome,.*
action: keep
- source_labels: [__meta_consul_service]
target_label: job
3、创建secret资源
kubectl create secret generic additional-configs --from-file=prometheus-additional.yaml -n monitoring
4、增加additionalScrapeConfigs配置段
kubectl edit prometheus k8s -n monitoring
spec:
additionalScrapeConfigs:
name: additional-configs
key: prometheus-additional.yaml
...
5、修改prometheus-server的service account权限
kubectl edit clusterrole prometheus-k8s -n monitoring
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: prometheus-k8s
rules:
- apiGroups:
- ""
resources:
- nodes
- services
- endpoints
- pods
- nodes/proxy
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- configmaps
- nodes/metrics
verbs:
- get
- nonResourceURLs:
- /metrics
verbs:
- get
作者:wanghongwei
版权声明:本作品遵循<CC BY-NC-ND 4.0>版权协议,商业转载请联系作者获得授权,非商业转载请附上原文出处链接及本声明。