快捷菜单
常用功能一站直达
更多功能请点顶栏「快捷菜单」


1实验环境:
21、win10,vmwrokstation虚机;
32、k8s集群:3台centos7.6 1810虚机,1个master节点,2个node节点
4 k8s version:v1.22.2
5 containerd://1.5.51[root@master1 vm-operator]#helm repo add grafana https://grafana.github.io/helm-charts
2"grafana" has been added to your repositories
3[root@master1 vm-operator]#helm repo update-我们可以在 values 中提前定义数据源和内置一些 dashboard,如下所示:
1cat <<EOF | helm install grafana grafana/grafana -f -
2 datasources:
3 datasources.yaml:
4 apiVersion: 1
5 datasources:
6 - name: victoriametrics
7 type: prometheus
8 orgId: 1
9 url: http://vmselect-vmcluster-demo.default.svc.cluster.local:8481/select/0/prometheus/
10 access: proxy
11 isDefault: true
12 updateIntervalSeconds: 10
13 editable: true
14
15 dashboardProviders:
16 dashboardproviders.yaml:
17 apiVersion: 1
18 providers:
19 - name: 'default'
20 orgId: 1
21 folder: ''
22 type: file
23 disableDeletion: true
24 editable: true
25 options:
26 path: /var/lib/grafana/dashboards/default
27
28 dashboards:
29 default:
30 victoriametrics:
31 gnetId: 11176
32 revision: 18
33 datasource: victoriametrics
34 vmagent:
35 gnetId: 12683
36 revision: 7
37 datasource: victoriametrics
38 kubernetes:
39 gnetId: 14205
40 revision: 1
41 datasource: victoriametrics
42EOF
43
44
45
46NAME: grafana
47LAST DEPLOYED: Tue May 17 17:13:14 2022
48NAMESPACE: default
49STATUS: deployed
50REVISION: 1
51NOTES:
521. Get your 'admin' user password by running:
53
54 kubectl get secret --namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
55
562. The Grafana server can be accessed via port 80 on the following DNS name from within your cluster:
57
58 grafana.default.svc.cluster.local
59
60 Get the Grafana URL to visit by running these commands in the same shell:
61
62 export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=grafana" -o jsonpath="{.items[0].metadata.name}")
63 kubectl --namespace default port-forward $POD_NAME 3000
64
653. Login with the password from step 1 and the username: admin
66####################################################
67#### WARNING: Persistence is disabled!!! You will lose your data when ####
68#### the Grafana pod is terminated. ####
69####################################################
70#本次log
71W0818 12:14:16.833439 52050 warnings.go:70] policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
72W0818 12:14:16.835043 52050 warnings.go:70] policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
73W0818 12:14:17.014946 52050 warnings.go:70] policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
74W0818 12:14:17.015087 52050 warnings.go:70] policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
75NAME: grafana
76LAST DEPLOYED: Thu Aug 18 12:14:16 2022
77NAMESPACE: default
78STATUS: deployed
79REVISION: 1
80NOTES:
811. Get your 'admin' user password by running:
82
83 kubectl get secret --namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
84
852. The Grafana server can be accessed via port 80 on the following DNS name from within your cluster:
86
87 grafana.default.svc.cluster.local
88
89 Get the Grafana URL to visit by running these commands in the same shell:
90
91 export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=grafana" -o jsonpath="{.items[0].metadata.name}")
92 kubectl --namespace default port-forward $POD_NAME 3000
93
943. Login with the password from step 1 and the username: admin
95####################################################
96#### WARNING: Persistence is disabled!!! You will lose your data when ####
97#### the Grafana pod is terminated. ####
98#################################################### 1👉 说明:
2
3```yaml
4cat <<EOF | helm install grafana grafana/grafana -f -
5 datasources:
6 datasources.yaml:
7 apiVersion: 1
8 datasources:
9 - name: victoriametrics
10 type: prometheus
11 orgId: 1
12 url: http://vmselect-vmcluster-demo.default.svc.cluster.local:8481/select/0/prometheus/ #这里是指定了grafna数据源的
13 access: proxy
14 isDefault: true
15 updateIntervalSeconds: 10
16 editable: true
17
18 dashboardProviders:
19 dashboardproviders.yaml: #个人对这个不是太清楚呀。。。
20 apiVersion: 1
21 providers:
22 - name: 'default'
23 orgId: 1
24 folder: ''
25 type: file
26 disableDeletion: true
27 editable: true
28 options:
29 path: /var/lib/grafana/dashboards/default
30
31 dashboards: #注意:这里是默认安装在grafna里的dashboard
32 default:
33 victoriametrics:
34 gnetId: 11176
35 revision: 18
36 datasource: victoriametrics
37 vmagent:
38 gnetId: 12683
39 revision: 7
40 datasource: victoriametrics
41 kubernetes:
42 gnetId: 14205
43 revision: 1
44 datasource: victoriametrics
45EOF1☸ ➜ export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=grafana" -o jsonpath="{.items[0].metadata.name}")
2 kubectl --namespace default port-forward $POD_NAME 3000
3Forwarding from 127.0.0.1:3000 -> 3000
4Forwarding from [::1]:3000 -> 3000登录的用户名为 admin,密码可以通过下面的命令获取:
1[root@master1 ~]#kubectl get secret --namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
2GcVlzxMsneJoa8PDBeDMHHQmUeAfA9zAWRLmAM7i我们可以查看下 victoriametrics cluster 的 dashboard:
127.0.0.1:3000/dashboards

正常可以看到如下所示的页面:

这是因为默认情况下 VMAgent 会采集 VM 集群相关组件的指标,包括 vmagent 本身的,所以我们可以正常看到 VM 集群的 Dashboard。
注意:这里又和之前一样的现象……
利用kubectl --namespace default port-forward $POD_NAME 3000命令后,依然无法在本地用127.0.0.1:3000来访问
于是自己将grafana这个svc的类型变为NodePort,再访问就正常了:
1kubectl edit svc grafana
2……
3type: NodePort
4……
自己本次现象:


安装完成。😘
日历 · 精选 · 友链 · 更多
如果内容对你有帮助,欢迎请我喝杯咖啡 ☕



One的公众号
爱折腾博客的小白