1.下载资源:

 

[root@k8s-master-node1 ~]# git clone https://github.com/coreos/kube-prometheus.git
Cloning into 'kube-prometheus'...
remote: Enumerating objects: 13409, done.
remote: Counting objects: 100% (1908/1908), done.
remote: Compressing objects: 100% (801/801), done.
remote: Total 13409 (delta 1184), reused 1526 (delta 947), pack-reused 11501
Receiving objects: 100% (13409/13409), 6.65 MiB | 5.21 MiB/s, done.
Resolving deltas: 100% (8313/8313), done.
[root@k8s-master-node1 ~]# 

 2.kube-promethu版本与k8s版本匹配

进入到/root/kube-prometheus目录下,查看README.md,确认版本信息

最新版本提示不支持k8s1.18版本,需要到github上查看对应版本:

https://github.com/prometheus-operator/kube-prometheus

release-0.7只支持到k8s 1.19版本,因此切换到更小一个版本确认是否支持k8s 1.18

这里可以找到kube-prometheus 0.6版本支持k8s 1.18

 进入到/root/kube-prometheus目录下,

查看版本:

切换分支到0.6:

git checkout -b v0.6.0

查看分支:

3.配置prometheus

进入目录:cd /root/kube-prometheus/manifests

修改 grafana-service.yaml 文件,使用 nodepode 方式访问 grafana:

Modify the grafana-service.yaml file and use nodepode to access grafana:

[root@k8s-master manifests]# cat grafana-service.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: grafana
  name: grafana
  namespace: monitoring
spec:
  type: NodePort            #增加NodePort
  ports:
  - name: http
    port: 3000
    targetPort: http
    nodePort: 31100        #增加
  selector:
    app: grafana
[root@k8s-master manifests]#

修改 prometheus-service.yaml,改为 nodepode:

Modify prometheus-service.yaml to nodepode:

[root@k8s-master manifests]# cat prometheus-service.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    prometheus: k8s
  name: prometheus-k8s
  namespace: monitoring
spec:
  type: NodePort                #增加
  ports:
  - name: web
    port: 9090
    targetPort: web
    nodePort: 31200             #增加
  - name: reloader-web          #增加整个节点
    port: 8080
    targetPort: reloader-web
    nodePort: 31300
  selector:
    app: prometheus
    prometheus: k8s
  sessionAffinity: ClientIP

修改 alertmanager-service.yaml,改为 nodepode

Modify alertmanager-service.yaml to nodepode

[root@k8s-master manifests]# cat alertmanager-service.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    alertmanager: main
  name: alertmanager-main
  namespace: monitoring
spec:
  type: NodePort                    #增加
  ports:
  - name: web
    port: 9093
    targetPort: web
    nodePort: 31400                 #增加
  - name: reloader-web              #增加整个节点
    port: 8080
    targetPort: reloader-web
    nodePort: 31500
  selector:
    alertmanager: main
    app: alertmanager
  sessionAffinity: ClientIP
[root@k8s-master manifests]#

创建名称空间和CRD

Create namespace and CRD

[root@k8s-master manifests]# kubectl create -f /root/kube-prometheus/manifests/setup
namespace/monitoring created
customresourcedefinition.apiextensions.k8s.io/alertmanagers.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/podmonitors.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/prometheuses.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/prometheusrules.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/servicemonitors.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/thanosrulers.monitoring.coreos.com created
clusterrole.rbac.authorization.k8s.io/prometheus-operator created
clusterrolebinding.rbac.authorization.k8s.io/prometheus-operator created
deployment.apps/prometheus-operator created
service/prometheus-operator created
serviceaccount/prometheus-operator created

等待资源可用后,安装

After waiting for resources to be available, install

[root@k8s-master manifests]# kubectl create -f /root/kube-prometheus/manifests/

----省略---

[root@k8s-master manifests]#

删除方式1:一次性删除命令:

kubectl delete --ignore-not-found=true -f manifests/ -f manifests/setup

删除方式2:如果安装错误要删除 prometeus,跟apply相反的顺序delete即可

#先执行:
kubectl delete -f /root/kube-prometheus/manifests/
#在执行:
kubectl delete -f /root/kube-prometheus/manifests/setup

访问 Prometheus

Visit Prometheus

http://192.168.1.10:31200/targets

ce3579a8549c5a57f610137b3938c936.png

访问 Grafana

Visit Grafana

http://192.168.1.10:31100/

默认账号密码:admin/admin

658089eab1cef9781312b66f2fc03180.png

访问报警平台 AlertManager

Visit the alert platform AlertManager

http://192.168.1.10:31400/#/status

90e5bc2941447d022f9c9eb0e57005a4.png

Logo

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

更多推荐