Prometheus、Grafana 部署
Grafana是一个开源的度量分析与可视化套件。经常被用作基础设施的时间序列数据和应用程序分析的可视化,我们这里用它来做Kubernetes集群监控数据的可视化。
准备工作
截至当前,prometheus、grafana均采用最新的镜像包,在在第一次部署的时候grafana报了一个错误mkdir: cannot create directory '/var/lib/grafana/plugins': No such file or directory
,这是因为Grafana启动使用的用户和用户组都是472,造成对外挂存储没有权限。参考官方
开始部署
新建yaml文件
- monitor-namespace.yaml
1
2
3
4
5# cat monitor-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: monitoring
其他的文件均采用以前历史的,然后稍加修改,其他yaml文件,移除grafana-ingress.yaml
、prometheus-ingress.yaml
文件修改
grafana-deploy.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
52apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: grafana-core
namespace: monitoring
labels:
app: grafana
component: core
spec:
replicas: 1
template:
metadata:
labels:
app: grafana
component: core
spec:
containers:
- image: grafana/grafana:latest
name: grafana-core
imagePullPolicy: IfNotPresent
# env:
resources:
# keep request = limit to keep this container in guaranteed class
limits:
cpu: 100m
memory: 100Mi
requests:
cpu: 100m
memory: 100Mi
env:
# The following env variables set up basic auth twith the default admin user and admin password.
- name: GF_AUTH_BASIC_ENABLED
value: "true"
- name: GF_AUTH_ANONYMOUS_ENABLED
value: "false"
# - name: GF_AUTH_ANONYMOUS_ORG_ROLE
# value: Admin
# does not really work, because of template variables in exported dashboards:
# - name: GF_DASHBOARDS_JSON_ENABLED
# value: "true"
readinessProbe:
httpGet:
path: /login
port: 3000
# initialDelaySeconds: 30
# timeoutSeconds: 1
volumeMounts:
- name: grafana-persistent-storage
mountPath: /var/lib/grafana
volumes:
- name: grafana-persistent-storage
emptyDir: {}prometheus-deploy.yaml
1
2
3
4
5
6spec:
containers:
- image: prom/prometheus:latest
name: prometheus
command:
- "/bin/prometheus"prometheus-svc.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16---
kind: Service
apiVersion: v1
metadata:
labels:
app: prometheus
name: prometheus
namespace: monitoring
spec:
#type: NodePort
ports:
- port: 9090
targetPort: 9090
#nodePort: 30005
selector:
app: prometheusgrafana-svc.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16# cat grafana-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: grafana
namespace: monitoring
labels:
app: grafana
component: core
spec:
#type: NodePort
ports:
- port: 3000
selector:
app: grafana
component: core
执行创建
1 | # kubectl apply -f ./ |
检查部署
1 | # kubectl get pod,svc,deploy -n monitoring |
创建Ingress
prometheus Ingress
1 | # cat prometheus-Ingress.yaml |
grafana Ingress
1 | # cat grafana-Ingress.yaml |
执行创建
1 | # kubectl apply -f prometheus-Ingress.yaml |
在浏览器输入prometheus.xxlaila.cn访问prometheus,输入grafana.xxlaila.cn访问grafana。
访问prometheus
配置grafana
到grafana的官方下载对应的模版文件导入,就可以出图啦