在以往的分享中,有分享过使用Prometheus Operator来管理Prometheus。但,在此同时,又抛出了个问题:是手工将Prometheus部署到 Kubernetes 比较好还是使用Prometheus Operator来部署比较好?
对于技术的选型,往往是没有规定死是要用哪一项技术的,而是需要结合业务的需求、运维场景、自身对某项技术的掌握程度、以及其它更多的考量因素来共同决定的:
所以,选择手工部署还是 Prometheus Operator,应该基于具体场景和需求进行综合考虑,以便更好地满足业务和运维的要求。
下面分享手工将Prometheus部署到 Kubernetes 的yaml,关于使用Prometheus Operator部署可参考我之前的分享或者参考官方文档即可。
提示:本案例中使用Prometheus的数据目录所在的后端存储是rook-ceph,可将其修改为您已有的后端存储,如原生的ceph、nfs等等。
apiVersion: v1
kind: Namespace
metadata:
name: monitor
---
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-config
namespace: monitor
data:
prometheus.yml: |
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: prometheus-pvc
namespace: monitor
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi
storageClassName: rook-ceph-block
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: prometheus
name: prometheus
namespace: monitor
spec:
replicas: 1
selector:
matchLabels:
app: prometheus
template:
metadata:
labels:
app: prometheus
spec:
initContainers:
- name: "change-prometheus-data-dir-perm"
image: busybox
command: ["/bin/sh"]
args: ["-c", "chown -R 65534:65534 /prometheus"]
securityContext:
privileged: true
volumeMounts:
- name: prometheus-storage
mountPath: /prometheus
containers:
- image: prom/prometheus:latest
name: prometheus
ports:
- containerPort: 9090
protocol: TCP
volumeMounts:
- name: prometheus-storage
mountPath: /prometheus
- name: prometheus-config
mountPath: /etc/prometheus
readOnly: true
volumes:
- name: prometheus-config
configMap:
name: prometheus-config
- name: prometheus-storage
persistentVolumeClaim:
claimName: prometheus-pvc
---
apiVersion: v1
kind: Service
metadata:
labels:
app: prometheus
name: prometheus
namespace: monitor
spec:
ports:
- name: http-port
nodePort: 30090
port: 9090
protocol: TCP
targetPort: 9090
selector:
app: prometheus
type: NodePort
注意:在上面的yaml中,initContainers 的作用是确保 /prometheus 目录以及其子目录的权限正确,因为 Prometheus 进程通常需要以非特权用户运行。同时,由于该 initContainers 是以特权模式运行的,因此可以确保 Prometheus 容器能够以正确的方式访问挂载的卷,而不会因为权限问题导致运行异常。
本文转载于WX公众号:不背锅运维:https://mp.weixin.qq.com/s/JlCgx1mkHqcF2e_ZqkafEw
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。