prometheus 监控k8s集群

介绍

名称配置版本系统版本
master4核8G1.20.1centos7.6
node12核4G1.20.1centos7.6
node22核4G1.20.1centos7.6
node32核4G1.20.1centos7.6
prometheus-operator-v0.9.0-

prometheus-operator下载地址

prometheus-镜像下载地址

prometheus-包下载

镜像下载

下载镜像
docker pull newrain857/prometheus:alertmanager
docker pull newrain857/prometheus:blackbox-exporter
docker pull newrain857/prometheus:configmap-reload
docker pull newrain857/prometheus:kube-rbac-proxy
docker pull newrain857/prometheus:grafana
docker pull newrain857/prometheus:kube-state-metrics
docker pull newrain857/prometheus:node-exporter
docker pull newrain857/prometheus:prometheus-adapter
docker pull newrain857/prometheus:prometheus
docker pull newrain857/prometheus:prometheus-operator


修改镜像名称
docker tag newrain857/prometheus:alertmanager quay.io/prometheus/alertmanager:v0.22.2
docker tag newrain857/prometheus:blackbox-exporter quay.io/prometheus/blackbox-exporter:v0.19.0
docker tag newrain857/prometheus:configmap-reload jimmidyson/configmap-reload:v0.5.0
docker tag newrain857/prometheus:kube-rbac-proxy quay.io/brancz/kube-rbac-proxy:v0.11.0
docker tag newrain857/prometheus:grafana grafana/grafana:8.1.1
docker tag newrain857/prometheus:kube-state-metrics bitnami/kube-state-metrics:v2.1.1
docker tag newrain857/prometheus:node-exporter quay.io/prometheus/node-exporter:v1.2.2
docker tag newrain857/prometheus:prometheus-adapter k8s.gcr.io/prometheus-adapter/prometheus-adapter:v0.9.0
docker tag newrain857/prometheus:prometheus quay.io/prometheus/prometheus:v2.29.1
docker tag newrain857/prometheus:prometheus-operator quay.io/prometheus-operator/prometheus-operator:v0.49.0

服务安装

[root@k8s-master ~]# wget https://codeload.github.com/prometheus-operator/kube-prometheus/tar.gz/refs/tags/v0.9.0
[root@k8s-master ~]# tar xf v0.9.0
[root@k8s-master ~]# cd kube-prometheus-0.9.0/manifests

修改yaml文件

文件名称 alertmanager-service.yaml  grafana-service.yaml  promethes--service.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/component: prometheus
    app.kubernetes.io/name: prometheus
    app.kubernetes.io/part-of: kube-prometheus
    app.kubernetes.io/version: 2.26.0
    prometheus: k8s
  name: prometheus-k8s
  namespace: monitoring
spec:
  type: NodePort #新增
  ports:
  - name: web
    port: 9090
    targetPort: web
    nodePort: 30090  #新增  alertmanager-service.yaml=>30093  grafana-service.yaml=>30095  promethes--service.yaml=>30090
  selector:
    app: prometheus
    app.kubernetes.io/component: prometheus
    app.kubernetes.io/name: prometheus
    app.kubernetes.io/part-of: kube-prometheus

安装prometheus-operator

[root@k8s-master ~]# kubectl apply -f setup/
[root@k8s-master ~]# kubectl get pods -n monitoring # 查看pod全部RUNNING之后再执行后面指令
[root@k8s-master ~]# kubectl apply -f . 
[root@k8s-master ~]# kubectl get pods -n monitoring # 等待podRUNNING

查看custom metrics api

[root@k8s-master ~]# kubectl get apiservices -n monitoring | grep metrics
v1beta1.metrics.k8s.io                 monitoring/prometheus-adapter   True        3h52m

获取prometheus端口

[root@k8s-master ~]# kubectl get svc -n monitoring  | grep NodePort
alertmanager-main       NodePort    10.101.12.122    <none>        9093:30093/TCP               3h50m
grafana                 NodePort    10.109.2.214     <none>        3000:30095/TCP               3h50m
prometheus-k8s          NodePort    10.105.121.223   <none>        9090:30090/TCP               3h50m
ip:30093/#/status   查看报警配置
ip:30090            查看prometheus
ip:30095            查看grafana模版

页面展示

30090
67315bdbc3f9e3b95b615b04851c8f8b21ae512b

30093
b78d6d3dbcd1cb02d811393a1c1869b81c8567eb

30095
a5e5369683ed8122eff824dba647a03ca0f7f43d

导入grafana仪表盘

02f5ab5addb2383e0e34f1b5a6d6912fb54b4a9a

仪表盘id 13105 、8919
8ebc9cfb7fd8cd5c536284c9bff8e8751a43fb39

13105
89ab260d150c5e4cb8d54af03a8200d28aa8ba43

8919
b44e0f0855517cc9f8c7e5ad14b9d66a370b8bbe

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐