--- weight: 4 title: Getting started with VM Operator menu: docs: parent: "guides" weight: 4 aliases: - /guides/getting-started-with-vm-operator.html --- **The guide covers:** * The setup of a [VM Operator](https://github.com/VictoriaMetrics/helm-charts/tree/master/charts/victoria-metrics-operator) via Helm in [Kubernetes](https://kubernetes.io/) with Helm charts. * The setup of a [VictoriaMetrics Cluster](https://docs.victoriametrics.com/cluster-victoriametrics/) via [VM Operator](https://github.com/VictoriaMetrics/helm-charts/tree/master/charts/victoria-metrics-operator). * How to add CRD for a [VictoriaMetrics Cluster](https://docs.victoriametrics.com/cluster-victoriametrics/) via [VM Operator](https://github.com/VictoriaMetrics/helm-charts/tree/master/charts/victoria-metrics-operator). * How to visualize stored data * How to store metrics in [VictoriaMetrics](https://victoriametrics.com) **Preconditions** * [Kubernetes cluster 1.20.9-gke.1001](https://cloud.google.com/kubernetes-engine). We use a GKE cluster from [GCP](https://cloud.google.com/) but this guide also applies to any Kubernetes cluster. For example, [Amazon EKS](https://aws.amazon.com/ru/eks/). * [Helm 3](https://helm.sh/docs/intro/install). * [kubectl 1.21+](https://kubernetes.io/docs/tasks/tools/install-kubectl). ## 1. VictoriaMetrics Helm repository See how to work with a [VictoriaMetrics Helm repository in previous guide](https://docs.victoriametrics.com/guides/k8s-monitoring-via-vm-cluster.html#1-victoriametrics-helm-repository). ## 2. Install the VM Operator from the Helm chart ```sh helm install vmoperator vm/victoria-metrics-operator ``` The expected output is: ```sh NAME: vmoperator LAST DEPLOYED: Thu Sep 30 17:30:30 2021 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: victoria-metrics-operator has been installed. Check its status by running: kubectl --namespace default get pods -l "app.kubernetes.io/instance=vmoperator" 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. ``` Run the following command to check that VM Operator is up and running: ```sh kubectl --namespace default get pods -l "app.kubernetes.io/instance=vmoperator" ``` The expected output: ```sh NAME READY STATUS RESTARTS AGE vmoperator-victoria-metrics-operator-67cff44cd6-s47n6 1/1 Running 0 77s ``` ## 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](https://docs.victoriametrics.com/cluster-victoriametrics/) via [VM Operator](https://github.com/VictoriaMetrics/helm-charts/tree/master/charts/victoria-metrics-operator):
```sh cat << EOF | kubectl apply -f - apiVersion: operator.victoriametrics.com/v1beta1 kind: VMCluster metadata: name: example-vmcluster-persistent spec: # Add fields here retentionPeriod: "12" vmstorage: replicaCount: 2 vmselect: replicaCount: 2 vminsert: replicaCount: 2 EOF ``` The expected output: ```sh vmcluster.operator.victoriametrics.com/example-vmcluster-persistent created ``` * By applying this CRD we install the [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/) to the default [namespace](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/) of your k8s cluster with following params: * `retentionPeriod: "12"` defines the [retention](https://docs.victoriametrics.com/single-server-victoriametrics/#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: ```sh kubectl get pods | grep vmcluster ``` The expected output: ```sh NAME READY STATUS RESTARTS AGE vminsert-example-vmcluster-persistent-845849cb84-9vb6f 1/1 Running 0 5m15s vminsert-example-vmcluster-persistent-845849cb84-r7mmk 1/1 Running 0 5m15s vmselect-example-vmcluster-persistent-0 1/1 Running 0 5m21s vmselect-example-vmcluster-persistent-1 1/1 Running 0 5m21s vmstorage-example-vmcluster-persistent-0 1/1 Running 0 5m25s vmstorage-example-vmcluster-persistent-1 1/1 Running 0 5m25s ``` There is an extra command to get information about the cluster state: ```sh kubectl get vmclusters ``` The expected output: ```text NAME INSERT COUNT STORAGE COUNT SELECT COUNT AGE STATUS example-vmcluster-persistent 2 2 2 5m53s operational ``` Internet traffic goes through the Kubernetes Load balancer which use the set of Pods targeted by a [Kubernetes Service](https://kubernetes.io/docs/concepts/services-networking/service/). The service in [VictoriaMetrics Cluster architecture](https://docs.victoriametrics.com/cluster-victoriametrics/#architecture-overview) 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: ```sh kubectl get svc | grep vminsert ``` The expected output: ```sh vminsert-example-vmcluster-persistent ClusterIP 10.107.47.136