[TOC]

快速搭建 grafana 可视化平台

项目地址: https://github.com/grafana/grafana/
官方地址: https://grafana.com

安装部署

步骤 01.资源清单(granana.ini)与 (Deployment)部署资源清单。

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
tee grafana.ini <<'EOF'
[server]
domain = devops.weiyigeek.top
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
serve_from_sub_path = true
EOF

tee grafana-deploy.yaml <<'EOF'
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: grafana-pvc
namespace: dashboard
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: grafana
name: grafana
namespace: dashboard
spec:
selector:
matchLabels:
app: grafana
template:
metadata:
labels:
app: grafana
spec:
securityContext:
fsGroup: 472
supplementalGroups:
- 0
containers:
- name: grafana
image: grafana/grafana:9.0.2
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
name: http-grafana
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /robots.txt
port: 3000
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 2
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 3000
timeoutSeconds: 1
resources:
requests:
cpu: 512m
memory: 1024Mi
volumeMounts:
- mountPath: /var/lib/grafana
name: grafana-pv
- mountPath: /etc/grafana/grafana.ini
name: ge-config
subPath: grafana.ini
volumes:
- name: grafana-pv
persistentVolumeClaim:
claimName: grafana-pvc
- name: ge-config
configMap:
name: ge-config
items:
- key: grafana.ini
path: grafana.ini
---
apiVersion: v1
kind: Service
metadata:
name: grafana
namespace: dashboard
spec:
ports:
- port: 3000
protocol: TCP
targetPort: http-grafana
selector:
app: grafana
sessionAffinity: None
type: LoadBalancer
EOF

步骤 02.创建 grafana.ini 的 configmap 以及部署 grafana 到集群中

1
2
kubectl create configmap ge-config --from-file=grafana.ini --namespace dashboard
kubectl create -f grafana-deploy.yaml --namespace dashboard

步骤 03.部署情况与日志情况查看。

1
2
3
kubectl logs -f --tail 50 -n dashboard -l app=grafana
# 关键日志:
# logger=http.server t=2022-07-14T07:24:25.409774065Z level=info msg="HTTP Server Listen" address=[::]:3000 protocol=http subUrl=/grafana socket=

步骤 04.配置 grafana ingress 的资源清单我们便可通过域名+grafana目录的方式进行访问。

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
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
ingressclass.kubernetes.io/is-default-class: "true"
nginx.ingress.kubernetes.io/client-body-buffer-size: 50m
nginx.ingress.kubernetes.io/proxy-body-size: 50m
nginx.ingress.kubernetes.io/proxy-buffer-size: 50m
nginx.ingress.kubernetes.io/proxy-buffering: "on"
nginx.ingress.kubernetes.io/proxy-buffers-number: "4"
nginx.ingress.kubernetes.io/proxy-connect-timeout: 60s
nginx.ingress.kubernetes.io/proxy-read-timeout: 120s
nginx.ingress.kubernetes.io/proxy-send-timeout: 120s
nginx.ingress.kubernetes.io/rewrite-target: /$2
labels:
app: devops
ref: devops
url: devops.weiyigeek.top
name: devops-weiyigeek
namespace: dashboard
spec:
ingressClassName: nginx
rules:
- host: devops.weiyigeek.top
http:
paths:
- backend:
service:
name: grafana
port:
number: 3000
path: /grafana(/|$)(.*)
pathType: ImplementationSpecific
tls:
- hosts:
- devops.weiyigeek.top
secretName: weiyigeek.top

温馨提示: 在进行前面操作完毕后我们便可通过https://devops.weiyigeek.top/grafana/login域名地址进行访问,默认密码 admin。

WeiyiGeek.Grafana之serve_from_sub_path设置

WeiyiGeek.Grafana之serve_from_sub_path设置