03、Prometheus监控:prometheus部署grapfana展示

prometheus部署grapfana展示

grafana 是一个可视化面板,有着非常漂亮的图表和布局展示,功能齐全的度量仪表盘和图形编辑器,支持 Graphite、zabbix、InfluxDB、Prometheus、OpenTSDB、Elasticsearch 等作为数据源,比 Prometheus 自带的图表展示功能强大太多,更加灵活,有丰富的插件,功能更加强大。

创建grafana6.0+版本

apiVersion: v1
kind: PersistentVolume
metadata:
  name: grafana
spec:
  capacity:
    storage: 1Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  nfs:
    path: /data/volumes/v3
    server: 10.6.76.25
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: grafana
  namespace: kube-system
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
apiVersion: batch/v1
kind: Job
metadata:
  name: grafana-chown
  namespace: kube-system
spec:
  template:
    spec:
      restartPolicy: Never
      containers:
      - name: grafana-chown
        command: ["chown", "-R", "472:472", "/var/lib/grafana"]
        image: busybox
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - name: storage
          subPath: grafana
          mountPath: /var/lib/grafana
      volumes:
      - name: storage
        persistentVolumeClaim:
          claimName: grafana
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: grafana
  namespace: kube-system
  labels:
    app: grafana
spec:
  revisionHistoryLimit: 10
  template:
    metadata:
      labels:
        app: grafana
    spec:
      containers:
      - name: grafana
        image: grafana/grafana:6.2.5
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3000
          name: grafana
        env:
        - name: GF_SECURITY_ADMIN_USER
          value: admin         #登录用户名
        - name: GF_SECURITY_ADMIN_PASSWORD
          value: admin       #登录密码
        readinessProbe:
          failureThreshold: 10
          httpGet:
            path: /api/health
            port: 3000
            scheme: HTTP
          initialDelaySeconds: 60
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 30
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /api/health
            port: 3000
            scheme: HTTP
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          limits:
            cpu: 100m
            memory: 256Mi
          requests:
            cpu: 100m
            memory: 256Mi
        volumeMounts:
        - mountPath: /var/lib/grafana
          subPath: grafana
          name: storage
      securityContext:
        fsGroup: 472
        runAsUser: 472
      volumes:
      - name: storage
        persistentVolumeClaim:
          claimName: grafana
---
apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: kube-system
  labels:
    app: grafana
spec:
  type: NodePort
  ports:
    - port: 3000
  selector:
    app: grafana
[root@k8s-master prometheus]# kubectl apply -f grafana.yaml
persistentvolume/grafana unchanged
job.batch/grafana-chown created
deployment.extensions/grafana created
service/grafana created
[root@k8s-master prometheus]# 
oot@k8s-master prometheus]#
[root@k8s-master prometheus]# kubectl get deploy,svc,pod  -n kube-system -o wide| grep grafana

deployment.extensions/grafana                    1/1     1            1           161m   grafana                            grafana/grafana:6.2.5                                                                    app=grafana

service/grafana                    NodePort    10.107.66.233    <none>        3000:32723/TCP           175m    app=grafana
pod/grafana-74bbff4858-nnfp8                  1/1     Running     0          161m    10.254.2.134   k8s-node-2   <none>           <none>
pod/grafana-chown-8gc2q                       0/1     Completed   0          176m    10.254.2.132   k8s-node-2   <none>           <none>
[root@k8s-master prometheus]#

修改数据源

*

这个地址一般是K8S内网svc地址,如果你忘记了,请弄个dig看一下

[root@k8s-master ~]#  kubectl get svc -n kube-system
NAME                       TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
custom-metrics-apiserver   ClusterIP   10.110.175.216   <none>        443/TCP                  42m
kube-dns                   ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   14d
kube-state-metrics         ClusterIP   10.110.101.22    <none>        8080/TCP,8081/TCP        54m
kubernetes-dashboard       NodePort    10.104.175.223   <none>        443:30080/TCP            7d21h
metrics-server             ClusterIP   10.102.159.167   <none>        443/TCP                  14d
monitoring-grafana         NodePort    10.99.103.174    <none>        80:31599/TCP             18m
node-exporter              ClusterIP   None             <none>        9100/TCP                 92m
prometheus                 NodePort    10.111.156.156   <none>        9090:31500/TCP           162m
 [root@k8s-master ~]# cat dig.yaml
apiVersion: v1
kind: Pod
metadata:
  name: dig
  namespace: kube-system
spec:
  containers:
  - name: dig
    image:  docker.io/azukiapp/dig
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
  restartPolicy: Always

[root@k8s-master ~]# kubectl exec -it dig /bin/bash -n kube-system
bash-4.3# nslookup prometheus
Server:         10.96.0.10
Address:        10.96.0.10#53

Name:   prometheus.kube-system.svc.cluster.local
Address: 10.111.156.156

bash-4.3#
bash-4.3#

*

*

*

*

自带的模板都很low

stats

*

stats 2.0

*

但是,grafana自带的模板和数据有些不匹配,我们可以去grafana官网去下载应用于k8s使用的模板,地址为:https://grafana.com/dashboards

访问grafana官网搜索k8s相关模板,有时搜索框点击没有反应,可以直接在URL后面加上搜索内容即可,需要什么样的模板,接下来具体监控再写

或者直接使用grafana的k8s插件,这是最好的。

这是只是先部署grafana

版权声明:本文不是「本站」原创文章,版权归原作者所有 | 原文地址: