others linux服务器运维 django3 监控 k8s golang 数据库 大数据 前端 devops 理论基础 java oracle 运维日志

prometheus监控Kubernetes 1.18.2

访问量:1510 创建时间:2020-04-30

下载kube-prometheus

官方地址:https://github.com/coreos/kube-prometheus/releases

因为我的版本时1.18.2 这里使用v0.5.0版本的kube-prometheus,可以下载Source code (tar.gz),版本兼容性查看下表

kube-prometheus stack Kubernetes 1.14 Kubernetes 1.15 Kubernetes 1.16 Kubernetes 1.17 Kubernetes 1.18
release-0.3
release-0.4
release-0.5
HEAD

安装kube-prometheus

[root@k8s-n1 prometheus]# tar xf kube-prometheus-0.5.0.tar.gz
#修改prometheus,granafa,alertmanager的service服务的端口从clusterip改为NodePort方式:
[root@k8s-n1 kube-prometheus-0.5.0]# cat manifests/prometheus-service.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    prometheus: k8s
  name: prometheus-k8s
  namespace: monitoring
spec:
  ports:
  - name: web
    nodePort: 30090  #add
    port: 9090
    targetPort: web
  selector:
    app: prometheus
    prometheus: k8s
  sessionAffinity: ClientIP
  type: NodePort  #add
[root@k8s-n1 kube-prometheus-0.5.0]# cat manifests/grafana-service.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: grafana
  name: grafana
  namespace: monitoring
spec:
  type: NodePort  #add
  ports:
  - name: http
    nodePort: 30000   #add
    port: 3000
    targetPort: http
  selector:
    app: grafana
[root@k8s-n1 kube-prometheus-0.5.0]# cat manifests/alertmanager-service.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    alertmanager: main
  name: alertmanager-main
  namespace: monitoring
spec:
  type: NodePort    #add
  ports:
  - name: web
    nodePort: 30093   #add
    port: 9093
    targetPort: web
  selector:
    alertmanager: main
    app: alertmanager
  sessionAffinity: ClientIP
#开始安装
[root@k8s-n1 kube-prometheus-0.5.0]# kubectl create -f manifests/setup/
[root@k8s-n1 kube-prometheus-0.5.0]# kubectl create -f manifests/
#等待所有的pod都启动完成Running
[root@k8s-n1 kube-prometheus-0.5.0]# kubectl get pod -n monitoring
NAME                                   READY   STATUS    RESTARTS   AGE
alertmanager-main-0                    2/2     Running   0          164m
alertmanager-main-1                    2/2     Running   0          164m
alertmanager-main-2                    2/2     Running   0          164m
grafana-5c55845445-srcfk               1/1     Running   0          164m
kube-state-metrics-957fd6c75-7l8pn     3/3     Running   0          164m
node-exporter-n5fr9                    2/2     Running   0          164m
node-exporter-qwbck                    2/2     Running   0          164m
node-exporter-rmw7h                    2/2     Running   0          164m
node-exporter-vsw2k                    2/2     Running   0          164m
prometheus-adapter-5949969998-scttc    1/1     Running   0          164m
prometheus-k8s-0                       3/3     Running   1          164m
prometheus-k8s-1                       3/3     Running   1          164m
prometheus-operator-574fd8ccd9-xrqn5   2/2     Running   0          164m

访问

通过nodeip:port访问你的prometheus ,grafana(默认账号密码admin,admin) ,alertmanager

这里演示一下granafa访问:

通过账号admin,密码admin访问NODEIP:30000访问granafa,先查看默认数据源-》点击prometheu

测试数据源(点击test可以显示正常),import3个dashboard

查看监控项目,点击左上角图标,点击Default Dashboard,可以查看已有的Dashboards

登陆评论: 使用GITHUB登陆