grafana官方dockerhub地址

grafana官方github地址

grafana官网

准备镜像

1
2
3
4
5
[root@ops-200 ~]# docker pull grafana/grafana:6.7.2
[root@ops-200 ~]# docker images|grep grafana
grafana/grafana 6.7.2 322e0a666176 10 days ago 233MB
[root@ops-200 ~]# docker tag 322e0a666176 harbor.od.com/infra/grafana:v6.7.2
[root@ops-200 ~]# docker push harbor.od.com/infra/grafana:v6.7.2

准备资源配置清单

创建资源目录

1
2
3
[root@ops-200 ~]# mkdir /data/k8s-yaml/grafana
[root@ops-200 ~]# cd /data/k8s-yaml/grafana
[root@ops-200 grafana]# mkdir /data/nfs-volume/grafana

编写yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
[root@ops-200 grafana]# vim 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@ops-200 grafana]# vim deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: grafana
name: grafana
name: grafana
namespace: infra
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 7
selector:
matchLabels:
name: grafana
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: grafana
name: grafana
spec:
containers:
- name: grafana
image: harbor.od.com/infra/grafana:v6.7.2
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
protocol: TCP
volumeMounts:
- mountPath: /var/lib/grafana
name: data
imagePullSecrets:
- name: harbor
securityContext:
runAsUser: 0
volumes:
- nfs:
server: ops-200.host.com
path: /data/nfs-volume/grafana
name: data

[root@ops-200 grafana]# vim service.yaml
apiVersion: v1
kind: Service
metadata:
name: grafana
namespace: infra
spec:
ports:
- port: 3000
protocol: TCP
targetPort: 3000
selector:
app: grafana

[root@ops-200 grafana]# vim 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

应用资源配置清单

1
2
3
4
5
6
7
8
9
[root@ops-200 grafana]# kubectl apply -f rbac.yaml 
clusterrole.rbac.authorization.k8s.io/grafana created
clusterrolebinding.rbac.authorization.k8s.io/grafana created
[root@ops-200 grafana]# kubectl apply -f deployment.yaml
deployment.apps/grafana created
[root@ops-200 grafana]# kubectl apply -f service.yaml
service/grafana created
[root@ops-200 grafana]# kubectl apply -f ingress.yaml
ingress.extensions/grafana created

安装插件

1
2
3
4
5
6
7
8
9
10
[root@ops-200 grafana]# kubectl get pod -ninfra|grep grafana
grafana-766ccf4fcd-9qwn7 1/1 Running 0 4m48s
[root@ops-200 grafana]# kubectl exec -it grafana-766ccf4fcd-9qwn7 bash -n infra
bash-5.0# grafana-cli plugins install grafana-kubernetes-app
bash-5.0# grafana-cli plugins install grafana-clock-panel
bash-5.0# grafana-cli plugins install grafana-piechart-panel
bash-5.0# grafana-cli plugins install briangann-gauge-panel
bash-5.0# grafana-cli plugins install natel-discrete-panel
[root@ops-200 grafana]# kubectl delete pod grafana-766ccf4fcd-9qwn7 -n infra
pod "grafana-766ccf4fcd-9qwn7" deleted

添加数据源

添加prometheus

image-20200413165018098

复制证书

image-20200413164903542

k8s插件配置

image-20200413165651469

复制证书

image-20200413165740480

dashboard展示

2365689674845