准备基础镜像

https://hub.docker.com/r/grafana/grafana
https://github.com/grafana/grafana
https://grafana.com/

[root@k8s7-200.host.com /opt/src]# docker image tag 6f18ddf9e552 harbor.od.com/infra/grafana:v5.4.2
[root@k8s7-200.host.com /opt/src]# docker push harbor.od.com/infra/grafana:v5.4.2

准备资源配置清单

[root@k8s7-200.host.com /data/k8s-yaml/grafana]# cat rbac.yaml 
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
    kubernetes.io/cluster-service: "true"
  name: grafana
rules:
- apiGroups:
  - "*"
  resources:
  - namespaces
  - deployments
  - pods
  verbs:
  - get
  - list
  - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
    kubernetes.io/cluster-service: "true"
  name: grafana
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: grafana
subjects:
- kind: User
  name: k8s-node

[root@k8s7-200.host.com /data/k8s-yaml/grafana]# cat deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: grafana
    name: grafana
  name: grafana
  namespace: infra
spec:
  replicas: 1
  selector:
    matchLabels:
      name: grafana
  template:
    metadata:
      labels:
        app: grafana
        name: grafana
    spec:
      containers:
      - name: grafana
        image: harbor.od.com/infra/grafana:v5.4.2
        ports:
        - containerPort: 3000
          protocol: TCP
        volumeMounts:
        - mountPath: /var/lib/grafana
          name: data
      imagePullSecrets:
      - name: harbor
      securityContext:
        runAsUser: 0
      volumes:
      - nfs:
          server: k8s7-200
          path: /data/nfs-volume/grafana
        name: data

[root@k8s7-200.host.com /data/k8s-yaml/grafana]# cat service.yaml 
apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: infra
spec:
  ports:
  - port: 3000
    protocol: TCP
  selector:
    app: grafana
  type: ClusterIP

[root@k8s7-200.host.com /data/k8s-yaml/grafana]# cat ingress.yaml 
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: grafana
  namespace: infra
spec:
  rules:
  - host: grafana.od.com
    http:
      paths:
      - path: /
        backend:
          serviceName: grafana
          servicePort: 3000

[root@k8s7-200.host.com /data/k8s-yaml/grafana]# mkdir -p /data/nfs-volume/grafana

DNS解析

grafana	  	   A	10.4.7.10

应用资源配置清单

[root@k8s7-22.host.com ~]# kubectl apply -f http://k8s-yaml.od.com/grafana/rbac.yaml
clusterrole.rbac.authorization.k8s.io/grafana created
clusterrolebinding.rbac.authorization.k8s.io/grafana created
[root@k8s7-22.host.com ~]# kubectl apply -f http://k8s-yaml.od.com/grafana/deployment.yaml
deployment.apps/grafana created
[root@k8s7-22.host.com ~]# kubectl apply -f http://k8s-yaml.od.com/grafana/service.yaml
service/grafana created
[root@k8s7-22.host.com ~]# kubectl apply -f http://k8s-yaml.od.com/grafana/ingress.yaml
ingress.extensions/grafana created

浏览器验证

在这里插入图片描述
在这里插入图片描述

安装插件

k8s-app插件

安装方法一:
grafana-cli plugins install grafana-kubernetes-app
在这里插入图片描述
安装方法二:
https://grafana.com/api/plugins/grafana-kubernetes-app/versions/1.0.1/download


[root@hdss7-21 plugins]# wget https://grafana.com/api/plugins/grafana-kubernetes-app/versions/1.0.1/download -O grafana-kubernetes-app.zip

[root@hdss7-200 plugins]# unzip grafana-kubernetes-app.zip

时钟插件 Clock Pannel

grafana-cli plugins install grafana-clock-panel

饼图插件 Pie Chart

grafana-cli plugins install grafana-piechart-panel

D3 Gauge

grafana-cli plugins install briangann-gauge-panel

Discrete插件

grafana-cli plugins install natel-discrete-panel

重启Pod

检查插件

在这里插入图片描述

接入普罗米修斯

在这里插入图片描述
在这里插入图片描述

部分展示

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Logo

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

更多推荐