☸ ➜ helm show values vm/victoria-metrics-operator > values.yaml
#这里直接把这个chart包给fetch下来[root@master1 vm-operator]#helm fetch vm/victoria-metrics-operator[root@master1 vm-operator]#ll -h victoria-metrics-operator-0.11.3.tgz -rw-r--r-- 1 root root 212K Aug 15 17:13 victoria-metrics-operator-0.11.3.tgz
[root@master1 vm-operator]#tar xf victoria-metrics-operator-0.11.3.tgz [root@master1 vm-operator]#cd victoria-metrics-operator/[root@master1 victoria-metrics-operator]#ls
Chart.yaml README.md README.md.gotmpl templates values.yaml
[root@master1 victoria-metrics-operator]#cat values.yaml # Default values for victoria-metrics.# This is a YAML-formatted file.# Declare variables to be passed into your templates.image:# -- Image repositoryrepository: victoriametrics/operator
# -- Image tagtag: v0.26.2
# -- Image pull policypullPolicy: IfNotPresent
# -- enables CRD creation and management.# -- with this option, if you remove this chart, all crd resources will be deleted with it.createCRD:true# -- uses legacy CRD api v1beta# -- it must be enabled for kubernetes version below 1.16useLegacyCRD:falsereplicaCount:1# -- Secret to pull imagesimagePullSecrets:[]# -- VM operatror deployment name overridenameOverride:""# -- Overrides the full name of server componentfullnameOverride:""# -- VM operator log level# -- possible values: info and error.logLevel:"info"rbac:# -- Specifies whether the RBAC resources should be createdcreate:truepspEnabled:true# -- Labels to be added to the all resourcesextraLabels:{}# extra Labels for Pods onlypodLabels:{}# -- Annotations to be added to the all resourcesannotations:{}securityContext:{}operator:# -- By default, operator converts prometheus-operator objects.disable_prometheus_converter:false# -- By default, operator creates psp for its objects.psp_auto_creation_enabled:true# -- Enables ownership reference for converted prometheus-operator objects,# it will remove corresponding victoria-metrics objects in case of deletion prometheus one.enable_converter_ownership:false# -- Enables custom config-reloader, bundled with operator.# It should reduce vmagent and vmauth config sync-time and make it predictable.useCustomConfigReloader:falseserviceAccount:# -- Specifies whether a service account should be createdcreate:true# -- The name of the service account to use. If not set and create is true, a name is generated using the fullname templatename:""# -- Resource objectresources:{}# limits:# cpu: 120m# memory: 320Mi# requests:# cpu: 80m# memory: 120Mi# -- Pod's node selector. Ref: [https://kubernetes.io/docs/user-guide/node-selection/](https://kubernetes.io/docs/user-guide/node-selection/nodeSelector:{}# -- Array of tolerations object. Ref: [https://kubernetes.io/docs/concepts/configuration/assign-pod-node/](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/)tolerations:[]# -- Pod affinityaffinity:{}# -- extra settings for the operator deployment. full list Ref: [https://github.com/VictoriaMetrics/operator/blob/master/vars.MD](https://github.com/VictoriaMetrics/operator/blob/master/vars.MD) env:[]# - name: VM_VMSINGLEDEFAULT_VERSION# value: v1.43.0# -- Additional hostPath mountsextraHostPathMounts:[]# - name: certs-dir# mountPath: /etc/kubernetes/certs# subPath: ""# hostPath: /etc/kubernetes/certs# readOnly: true# -- Extra Volumes for the podextraVolumes:[]# - name: example# configMap:# name: example# -- Extra Volume Mounts for the containerextraVolumeMounts:[]# - name: example# mountPath: /exampleextraContainers:[]# - name: config-reloader# image: reloader-image# -- Configures resource validationadmissionWebhooks:# -- Enables validation webhook.enabled:false# -- What to do in case, when operator not available to validate request.policy: Fail
# -- Enables custom ca bundle, if you are not using cert-manager.# -- in case of custom ca, you have to create secret - {{chart-name}}-validation# -- with keys: tls.key, tls.crt, ca.crtcaBundle:""certManager:# -- Enables cert creation and injection by cert-manager.enabled:false# --If needed, provide own issuer. Operator will create self-signed if empty.issuer:{}
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
我们这里只对下面的内容做了修改:
vim values.yaml
# values.yamlrbac:# -- Specifies whether the RBAC resources should be createdcreate:truepspEnabled:falseoperator:# -- 默认情况下,vm-operator会转换prometheus-operator对象disable_prometheus_converter:false# -- 默认情况下,vm-operator会为它的对象创建psppsp_auto_creation_enabled:false# -- 启用转换后的 prometheus-operator 对象的所有权引用,如果删除 prometheus 对象,它将删除相应的 victoria-metrics 对象。enable_converter_ownership:false# -- Enables custom config-reloader, bundled with operator.# It should reduce vmagent and vmauth config sync-time and make it predictable.useCustomConfigReloader:true# -- 是否开启资源校验的准入控制器(生产环境建议开启)# admissionWebhooks:# # -- Enables validation webhook.# enabled: false# # -- What to do in case, when operator not available to validate request.# policy: Fail# # -- Enables custom ca bundle, if you are not using cert-manager.# # -- in case of custom ca, you have to create secret - {{chart-name}}-validation# # -- with keys: tls.key, tls.crt, ca.crt# caBundle: ""# certManager:# # -- Enables cert creation and injection by cert-manager.# enabled: false# # --If needed, provide own issuer. Operator will create self-signed if empty.# issuer: {}
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
3.安装
然后使用下面的命令即可一键安装 vm-operator:
[root@master1 vm-operator]#helm upgrade --install victoria-metrics-operator vm/victoria-metrics-operator -f values.yaml -n vm-operator --create-namespace
Release "victoria-metrics-operator" does not exist. Installing it now.
NAME: victoria-metrics-operator
LAST DEPLOYED: Mon Aug 1517:25:20 2022
NAMESPACE: vm-operator
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
victoria-metrics-operator has been installed. Check its status by running:
kubectl --namespace vm-operator get pods -l "app.kubernetes.io/instance=victoria-metrics-operator"
Get more information on https://github.com/VictoriaMetrics/helm-charts/tree/master/charts/victoria-metrics-operator.
See "Getting started guide for VM Operator" on https://docs.victoriametrics.com/guides/getting-started-with-vm-operator.html .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
4.验证
安装完成后可以查看 vm-operator 的状态来验证是否安装成功:
[root@master1 vm-operator]#helm ls -n vm-operator
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
victoria-metrics-operator vm-operator 12022-08-15 17:25:20.771034202 +0800 CST deployed victoria-metrics-operator-0.11.3 0.26.3
[root@master1 vm-operator]#kubectl --namespace vm-operator get pods -l "app.kubernetes.io/instance=victoria-metrics-operator"
NAME READY STATUS RESTARTS AGE
victoria-metrics-operator-5b98996ccc-5pcsg 1/1 Running 2(3m10s ago) 5m52s
☸ ➜ kubectl explain VMCluster.spec.vmstorage
KIND: VMCluster
VERSION: operator.victoriametrics.com/v1beta1
RESOURCE: vmstorage >
DESCRIPTION:>
FIELDS:
affinity <>
Affinity If specified, the pod's scheduling constraints.
configMaps <[]string>
ConfigMaps is a list of ConfigMaps in the same namespace as the VMSelect
object, which shall be mounted into the VMSelect Pods. The ConfigMaps are
mounted into /etc/vm/configs/-name>.
containers <[]>
Containers property allows to inject additions sidecars or to patch
existing containers. It can be useful for proxies, backup, etc.
dnsConfig >
Specifies the DNS parameters of a pod. Parameters specified here will be
merged to the generated DNS configuration based on DNSPolicy.
dnsPolicy >
DNSPolicy sets DNS policy for the pod
extraArgs
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
直接应用上面定义的对象:
[root@master1 vm-operator]#kubectl apply -f vmcluster-demo.yaml
vmcluster.operator.victoriametrics.com/vmcluster-demo created
[root@master1 vm-operator]#kubectl get vmcluster
NAME INSERT COUNT STORAGE COUNT SELECT COUNT AGE STATUS
vmcluster-demo 222 12s expanding
1
2
3
4
5
应用后 vm-operator 会 watch 到我们创建了该 CRD 对象,然后会根据我们的定义去自动创建对应的 VM 集群,也就是前面提到的几个组件服务:
[root@master1 vm-operator]#kubectl apply -f vmagent-demo.yaml
vmagent.operator.victoriametrics.com/vmagent-demo created
[root@master1 vm-operator]#kubectl get vmagent
NAME AGE
vmagent-demo 9s
接下来我们安装 Grafana 来验证 VM 集群,这里为了简单我们就直接使用 Helm Chart 进行安装:
[root@master1 vm-operator]#helm repo add grafana https://grafana.github.io/helm-charts"grafana" has been added to your repositories
[root@master1 vm-operator]#helm repo update
1
2
3
我们可以在 values 中提前定义数据源和内置一些 dashboard,如下所示:
cat <| helm install grafana grafana/grafana -f -datasources:datasources.yaml:apiVersion:1datasources:-name: victoriametrics
type: prometheus
orgId:1url: http://vmselect-vmcluster-demo.default.svc.cluster.local:8481/select/0/prometheus/
access: proxy
isDefault:trueupdateIntervalSeconds:10editable:truedashboardProviders:dashboardproviders.yaml:apiVersion:1providers:-name:'default'orgId:1folder:''type: file
disableDeletion:trueeditable:trueoptions:path: /var/lib/grafana/dashboards/default
dashboards:default:victoriametrics:gnetId:11176revision:18datasource: victoriametrics
vmagent:gnetId:12683revision:7datasource: victoriametrics
kubernetes:gnetId:14205revision:1datasource: victoriametrics
EOF
NAME: grafana
LAST DEPLOYED: Tue May 17 17:13:14 2022
NAMESPACE: default
STATUS: deployed
REVISION:1NOTES:1. Get your 'admin' user password by running:
kubectl get secret --namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
2. The Grafana server can be accessed via port 80 on the following DNS name from within your cluster:
grafana.default.svc.cluster.local
Get the Grafana URL to visit by running these commands in the same shell:
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}")
kubectl --namespace default port-forward $POD_NAME 3000
3. Login with the password from step 1 and the username: admin
#################################################################################################################### WARNING: Persistence is disabled!!! You will lose your data when ############## the Grafana pod is terminated. ##################################################################################################################
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
#本次log
W0818 12:14:16.833439 52050 warnings.go:70] policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
W0818 12:14:16.835043 52050 warnings.go:70] policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
W0818 12:14:17.014946 52050 warnings.go:70] policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
W0818 12:14:17.015087 52050 warnings.go:70] policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
NAME: grafana
LAST DEPLOYED: Thu Aug 18 12:14:16 2022
NAMESPACE: default
STATUS: deployed
REVISION:1NOTES:1. Get your 'admin' user password by running:
kubectl get secret --namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
2. The Grafana server can be accessed via port 80 on the following DNS name from within your cluster:
grafana.default.svc.cluster.local
Get the Grafana URL to visit by running these commands in the same shell:
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}")
kubectl --namespace default port-forward $POD_NAME 3000
3. Login with the password from step 1 and the username: admin
#################################################################################################################### WARNING: Persistence is disabled!!! You will lose your data when ############## the Grafana pod is terminated. ##################################################################################################################
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
2.查看victoriametrics cluster 的 dashboard
安装完成后可以使用上面提示的命令在本地暴露 Grafana 服务:
☸ ➜ exportPOD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=grafana" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace default port-forward $POD_NAME3000
Forwarding from 127.0.0.1:3000 ->3000
Forwarding from [::1]:3000 ->3000
[root@master1 vm-operator]#kubectl apply -f vmnode-exporter-scrape.yaml
vmnodescrape.operator.victoriametrics.com/node-exporter created
[root@master1 vm-operator]#kubectl get vmnodescrape
NAME AGE
node-exporter 5s
1
2
3
4
5
创建后 vmagent 就会自动去识别该对象去对 node-exporter 进行抓取了:
[root@master1 vm-operator]#kubectl port-forward svc/vmagent-vmagent-demo 8429:8429
Forwarding from 127.0.0.1:8429 ->8429
Forwarding from [::1]:8429 ->8429
Handling connection for8429
此外还可以通过 VMServiceScrape 去定义要抓取的 Service 服务(Endpoints),它基于选择器为 vmagent 生成抓取配置,如果想要抓取没有定义 Service 的 Pod 的指标,则可以通过 VMPodScrape 来进行定义,同样还有报警相关的也都有相应的 CRD 来进行管理。