The guide covers:
- The setup of a VM Operator via Helm in Kubernetes with Helm charts.
- The setup of a VictoriaMetrics Cluster via VM Operator.
- How to add CRD for a VictoriaMetrics Cluster via VM Operator.
- How to visualize stored data
- How to store metrics in VictoriaMetrics
Preconditions
- Kubernetes cluster 1.20.9-gke.1001. We use a GKE cluster from GCP but this guide also applies to any Kubernetes cluster. For example, Amazon EKS.
- Helm 3.
- kubectl 1.21+.
1. VictoriaMetrics Helm repository #
See how to work with a VictoriaMetrics Helm repository in previous guide.
2. Install the VM Operator from the Helm chart #
|
|
The expected output is:
|
|
Run the following command to check that VM Operator is up and running:
|
|
The expected output:
|
|
3. Install VictoriaMetrics Cluster #
For this example we will use default value for name: example-vmcluster-persistent
. Change it value up to your needs.
Run the following command to install VictoriaMetrics Cluster via VM Operator:
|
|
The expected output:
|
|
- By applying this CRD we install the VictoriaMetrics cluster to the default namespace of your k8s cluster with following params:
retentionPeriod: "12"
defines the retention to 12 months.replicaCount: 2
creates two replicas of vmselect, vminsert and vmstorage.
Please note that it may take some time for the pods to start. To check that the pods are started, run the following command:
|
|
The expected output:
|
|
There is an extra command to get information about the cluster state:
|
|
The expected output:
|
|
Internet traffic goes through the Kubernetes Load balancer which use the set of Pods targeted by a Kubernetes Service. The service in VictoriaMetrics Cluster architecture which accepts the ingested data named vminsert
and in Kubernetes it is a vminsert
service. So we need to use it for remote_write url.
To get the name of vminsert
services, please run the following command:
|
|
The expected output:
|
|
To scrape metrics from Kubernetes with a VictoriaMetrics Cluster we will need to install VMAgent with some additional configurations.
Copy vminsert-example-vmcluster-persistent
(or whatever user put into metadata.name field https://docs.victoriametrics.com/guides/getting-started-with-vm-operator.html#example-cluster-config) service name and add it to the remoteWrite
URL from quick-start example.
Here is an example of the full configuration that we need to apply:
|
|
The expected output:
|
|
remoteWrite.url
for VMAgent consists of the following parts:
“service_name.VMCluster_namespace.svc.kubernetes_cluster_domain” that in our case will look like vminsert-example-vmcluster-persistent.default.svc.cluster.local
Verify that VMAgent
is up and running by executing the following command:
|
|
The expected output is:
|
|
There are two containers for VMagent: the first one is a VMagent and the second one is a sidecar with a secret. VMagent use a secret with configuration which is mounted to the special sidecar. It observes the changes with configuration and send a signal to reload configuration for the VMagent.
Run the following command to make VMAgent
’s port accessible from the local machine:
|
|
The expected output is:
|
|
To check that VMAgent
collects metrics from the k8s cluster open in the browser http://127.0.0.1:8429/targets
.
You will see something like this:

VMAgent
connects to kubernetes service discovery and gets targets which needs to be scraped. This service discovery is controlled by VictoriaMetrics Operator
4. Verifying VictoriaMetrics cluster #
See how to install and connect Grafana to VictoriaMetrics but with one addition - we should get the name of vmselect
service from the freshly installed VictoriaMetrics Cluster because it will now be different.
To get the new service name, please run the following command:
|
|
The expected output:
|
|
The final config will look like this:
|
|
5. Check the result you obtained in your browser #
To check that VictoriaMetrics collecting metrics from the k8s cluster open in your browser http://127.0.0.1:3000/dashboards
and choose the VictoriaMetrics - cluster
dashboard. Use admin
for login and the password
that you previously got from kubectl.

The expected output is:

6. Summary #
- We set up Kubernetes Operator for VictoriaMetrics with using CRD.
- We collected metrics from all running services and stored them in the VictoriaMetrics database.