记录自己安装 Prometheus Operator 的过程
一、Prometheus Operator 介绍 kubernetes的监控系统Prometheus 应该都比较了解, 简述以下几点吧
1. Prometheus 简介 组件 Prometheus 由多个组件组成,但是其中许多组件是可选的:
Prometheus Server:用于抓取指标、存储时间序列数据
exporter:暴露指标让任务来抓
pushgateway:push 的方式将指标数据推送到该网关
alertmanager:处理报警的报警组件
adhoc:用于数据查询架构 下图是 Prometheus 官方提供的架构及其一些相关的生态系统组件:
2. Operator 简介 Operator 是 CoreOS 推出的旨在简化复杂有状态应用管理的框架,它是一个感知应用状态的控制器,通过扩展 Kubernetes API 来自动创建、管理和配置应用实例。
你可以在 OperatorHub.io 上查看 Kubernetes 社区推荐的一些 Operator 范例。
operator 架构图
二、安装依赖 安装Helm 1. 下载Helm Hlem版本我使用的是当前2版本中的最新版 2.16.7,因为官方建议使用2.14以上版本, 不然会有CRD相关问题, 具体见Github prometheus-operator
wget https://storage.googleapis.com/kubernetes-helm/helm-v2.16.7-linux-amd64.tar.gz tar zxvf helm-v2.16.7-linux-amd64.tar.gz mv linux-amd64/helm linux-amd64/tiller /usr/local /bin/ helm version
2. 创建RBAC 创建文件rbac-tiller.yaml , 内容为下
apiVersion: v1 kind: ServiceAccount metadata: name: tiller namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: tiller roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: tiller namespace: kube-system
创建RBAC
kubectl apply -f rbac-tiller.yaml
2. 初始化Helm 因为默认下载gcr.io仓库的镜像, 由于墙的原因下载失败, 所以我下载后传到了我司仓库
helm init --service-account tiller --tiller-image registry.cn-beijing.aliyuncs.com/roobo/tiller:v2.16.7 $ helm version Client: &version.Version{SemVer:"v2.16.7" , GitCommit:"5f2584fd3d35552c4af26036f0c464191287986b" , GitTreeState:"clean" } Server: &version.Version{SemVer:"v2.16.7" , GitCommit:"5f2584fd3d35552c4af26036f0c464191287986b" , GitTreeState:"clean" }
三、安装Prometheus-Operator 1. 创建Namespace (将相关PODs都创建到此NS下)
kubelet create ns monitoring
2. 安装 prometheus-operator helm install --namespace monitoring --name prometheus-operator stable/prometheus-operator
3. 查看相关PODs [root@k8smaster-01 ~] NAME READY STATUS RESTARTS AGE alertmanager-prometheus-operator-alertmanager-0 2/2 Running 0 53m prometheus-operator-grafana-69bfccc949-h9s7x 2/2 Running 0 53m prometheus-operator-kube-state-metrics-7ddcbdb744-xzh9w 1/1 Running 0 53m prometheus-operator-operator-6d4f47dc49-9g9jr 2/2 Running 0 53m prometheus-operator-prometheus-node-exporter-h9c2p 1/1 Running 0 53m prometheus-operator-prometheus-node-exporter-jw2hn 1/1 Running 0 53m prometheus-operator-prometheus-node-exporter-mqq4p 1/1 Running 0 53m prometheus-operator-prometheus-node-exporter-zxcg5 1/1 Running 0 53m prometheus-prometheus-operator-prometheus-0 3/3 Running 1 53m [root@k8smaster-01 ~] NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE alertmanager-operated ClusterIP None <none> 9093/TCP,9094/TCP,9094/UDP 53m prometheus-operated ClusterIP None <none> 9090/TCP 53m prometheus-operator-alertmanager ClusterIP 10.254.13.40 <none> 9093/TCP 54m prometheus-operator-grafana ClusterIP 10.254.0.159 <none> 80/TCP 54m prometheus-operator-kube-state-metrics ClusterIP 10.254.43.177 <none> 8080/TCP 54m prometheus-operator-operator ClusterIP 10.254.38.46 <none> 8080/TCP,443/TCP 54m prometheus-operator-prometheus ClusterIP 10.254.27.218 <none> 9090/TCP 54m prometheus-operator-prometheus-node-exporter ClusterIP 10.254.60.8 <none> 9100/TCP 54m [root@k8smaster-01 ~] NAME CREATED AT alertmanagers.monitoring.coreos.com 2020-05-10T06:38:44Z podmonitors.monitoring.coreos.com 2020-05-10T06:38:51Z prometheuses.monitoring.coreos.com 2020-05-10T06:38:56Z prometheusrules.monitoring.coreos.com 2020-05-10T06:39:02Z servicemonitors.monitoring.coreos.com 2020-05-10T06:39:07Z thanosrulers.monitoring.coreos.com 2020-05-10T06:39:12Z
4. 创建Ingress 默认情况下Grafana并不能直接访问, 可以将svc改为NodePort方式或者创建Ingress 通过域名的方式访问到, 这里以Ingress举例
Yaml文件 (将$DOMAIN修改为自己的域名)
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: ingress-prometheus-operator-grafana namespace: monitoring spec: rules: - host: $DOMAIN http: paths: - path: / backend: serviceName: prometheus-operator-grafana servicePort: 80
四、效果图