一、下载普罗米修斯配置清单
1.查看集群状态
[root@k8s-m-01 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-m-01 Ready control-plane,master 22d v1.21.3
k8s-n-01 Ready <none> 22d v1.21.3
k8s-n-02 Ready <none> 22d v1.21.3
2.下载代码
[root@k8s-master-01 ~]# git clone -b release-0.7 --single-branch https://github.com/prometheus-operator/kube-prometheus.git
# 或者
[root@k8s-master-01 ~]# wget https://github.com/prometheus-operator/kube-prometheus/archive/refs/tags/v0.7.0.tar.gz
3.解压
[root@k8s-master-01 ~]# tar xf kube-prometheus-0.7.0.tar.gz
4.部署
[root@k8s-m-01 ~]# cd kube-prometheus-0.7.0/manifests/setup/
[root@k8s-m-01 setup]# kubectl apply -f ./
#查看
[root@k8s-m-01 setup]# kubectl get pod -n monitoring
prometheus-operator-7649c7454f-6rcdd 2/2 Running 0 16m
[root@k8s-m-01 setup]# cd ..
[root@k8s-m-01 manifests]# pwd
/root/kube-prometheus-0.7.0/manifests
[root@k8s-m-01 manifests]# kubectl apply -f ./
#如果要卸载,先卸载manifests这个目录,再卸载setup,顺序不能搞反,会导致命名空间锁死
#如果拉取镜像失败,可以加谷歌的DNS
[root@k8s-m-01 manifests]# vim /etc/resolv.conf
# Generated by NetworkManager
nameserver 114.114.114.114
nameserver 8.8.8.8
~
5.创建ingress域名
[root@k8s-m-01 manifests]# mkdir ingress
[root@k8s-m-01 manifests]# cd ingress/
[root@k8s-m-01 ingress]# cat ingress.yaml
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: prometheus
namespace: monitoring
spec:
rules:
- host: "prometheus.test.com"
http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: prometheus-k8s
port:
number: 9090
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: grafana
namespace: monitoring
spec:
rules:
- host: "grafana.test.com"
http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: grafana
port:
number: 3000
# 启动
[root@k8s-m-01 ingress]# kubectl apply -f ingress.yaml
ingress.networking.k8s.io/prometheus created
ingress.networking.k8s.io/grafana created
6.查看本机映射端口
[root@k8s-m-01 ingress]# kubectl get svc -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller NodePort 10.108.202.150 <none> 80:31197/TCP,443:30826/TCP 12d
ingress-nginx-controller-admission ClusterIP 10.97.217.170 <none> 443/TCP 12d
7.配置本地hosts解析
192.168.15.31 linux.alert.com linux.grafana.com linux.prometheus.com
8.访问
linux.alert.com:31197
linux.grafana.com:31197
linux.prometheus.com:31197
二、检查grafana出图
1.登录
2.检查
https://grafana.com/grafana/dashboards