Operator部署Prometheus

一、介绍

Operator是CoreOS公司开发,用于扩展kubernetes API或特定应用程序的控制器,它用来创建、配置、管理复杂的有状态应用,例如数据库,监控系统。其中Prometheus-Operator就是其中一个重要的项目。

其中核心部分是Operator,它会去创建Prometheus、ServiceMonitor、AlertManager、PrometheusRule这4个CRD对象,然后会一直监控并维护这4个对象的状态。

  • Prometheus:作为Prometheus Server的抽象

  • ServiceMonitor:就是exporter的各种抽象

  • AlertManager:作为Prometheus AlertManager的抽象

  • PrometheusRule:实现报警规则的文件

上图中的 Service 和 ServiceMonitor 都是 Kubernetes 的资源,一个 ServiceMonitor 可以通过 labelSelector 的方式去匹配一类 Service,Prometheus 也可以通过 labelSelector 去匹配多个ServiceMonitor。

二、安装

安装方式:通过源码安装

git clone https://github.com/coreos/kube-prometheus.git     
(通过源码安装可能会导致集群权限不足的问题出现)

可参考 如下:

git clone https://gitee.com/Tsail/kube-prometheus.git
cat manifests/alertmanager-secret.yaml
cat manifests/setup/prometheus-operator-clusterRole.yaml
cd kube-prometheus/manifests/ServiceMonitor && ls

相关配置可进行优化调整。

我们进入kube-prometheus/manifests/setup,就可以直接创建CRD对象:

# cd kube-prometheus/manifests/setup
# kubectl apply -f .

然后在上层目录创建资源清单:

# cd kube-prometheus/manifests
# kubectl apply -f .

可以看到创建如下的CRD对象:

[root@jdo-dev-k8s-master-90 ~]# kubectl get crd | grep coreos
alertmanagers.monitoring.coreos.com           2021-08-19T10:45:23Z
podmonitors.monitoring.coreos.com             2021-08-19T10:45:23Z
prometheuses.monitoring.coreos.com            2021-08-19T10:45:23Z
prometheusrules.monitoring.coreos.com         2021-08-19T10:45:24Z
servicemonitors.monitoring.coreos.com         2021-08-19T10:45:24Z

查看创建的po

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 安装kubectl 在部署前需要安装kubectl,kubectl是kubernetes的命令行工具,用于管理kubernetes。kubectl安装文档可参考https://kubernetes.io/docs/tasks/tools/install-kubectl。 2. kubectl命令行工具配置 下载kubectl命令行工具后,需要对其进行配置以连接到kubernetes集群。kubectl配置可参考https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/。 3. 安装helm Helm是kubernetes的包管理工具,用于打包、发布和管理kubernetes应用程序。Helm安装文档可参考https://helm.sh/docs/intro/install/。 4. 部署prometheus-operator 在安装完helm后,使用helm命令行工具部署prometheus-operatorprometheus-operator的helm chart地址为https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack,可通过以下命令安装: ``` helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update helm install prometheus prometheus-community/kube-prometheus-stack ``` 5. 验证prometheus-operator部署 部署完成后,可以通过kubectl命令行工具查看部署状态,以验证是否已成功部署prometheus-operator。 ``` kubectl get pods -n prometheus ``` 输出内容如下: ``` prometheus-grafana-7b96cf655f-7tgts 2/2 Running 0 2m2s prometheus-kube-state-metrics-568b748cfc-mskcz 1/1 Running 0 2m2s prometheus-prometheus-node-exporter-566h7 1/1 Running 0 2m2s prometheus-prometheus-node-exporter-z6phj 1/1 Running 0 2m2s prometheus-prometheus-operator-5d6cd84c6f-rk77k 1/1 Running 0 2m2s prometheus-prometheus-adapter-7b784f5866-vdxzf 1/1 Running 0 2m2s ``` 如果输出内容中的所有pod都处于“Running”状态,则可以说明prometheus-operator已成功部署

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值