VMCluster represents a high-available and fault-tolerant version of VictoriaMetrics database.
The VMCluster CRD defines a cluster version VM.
For each VMCluster resource, the Operator creates:
VMStorage as StatefulSet,
VMSelect as StatefulSet
and VMInsert as deployment.
For VMStorage and VMSelect headless services are created. VMInsert is created as service with clusterIP.
There is a strict order for these objects creation and reconciliation:
VMStorage is synced - the Operator waits until all its pods are ready;
Then it syncs VMSelect with the same manner;
VMInsert is the last object to sync.
All statefulsets are created
with OnDelete update type.
It allows to manually manage the rolling update process for Operator by deleting pods one by one and waiting for the ready status.
Rolling update process may be configured by the operator env variables.
The most important is VM_PODWAITREADYTIMEOUT=80s - it controls how long to wait for pod’s ready status.
Operator provides enhanced load-balancing mechanism for vminsert and vmselect clients. By default, operator uses built-in Kubernetes service with clusterIP type for clients connection. It’s good solution for short lived connections. But it acts poorly with long-lived TCP sessions and leads to the uneven resources utilization for vmselect and vminsert components.
Consider the following example:
In this case clients could establish multiple connections to the same pod via service. And client requests will be served only by subset of pods.
Operator will deploy VMAuth deployment with 2 replicas. And update vminsert and vmselect services to point to vmauth.
In addition, operator will create 3 additional services with the following pattern:
vminsertinternal-CLUSTER_NAME - needed for vmselect pod discovery
vmselectinternal-CLUSTER_NAME - needed for vminsert pod discovery
vmclusterlb-CLUSTER_NAME - needed for metrics collection and exposing vmselect and vminsert components via VMAuth balancer.
Network scheme with load-balancing:
The requestsLoadBalancer feature works transparently and is managed entirely by the VMCluster operator,
with no direct access to the underlying VMAuth configuration.
If you need more control over load balancing behavior,
or want to combine request routing with authentication or (m)TLS,
consider deploying a standalone VMAuth resource instead of enabling requestsLoadBalancer.
VMCluster supports all listed in the above-mentioned articles parameters and features:
replicationFactor - the number of replicas for each metric.
for every component of cluster (vmstorage / vmselect / vminsert):
replicaCount - the number of replicas for components of cluster.
affinity - the affinity (the pod’s scheduling constraints) for components pods. See more details in kubernetes docs.
topologySpreadConstraints - controls how pods are spread across your cluster among failure-domains such as regions, zones, nodes, and other user-defined topology domains. See more details in kubernetes docs.
In addition, operator:
uses k8s services or vmauth for load balancing between vminsert and vmselect components,
uses health checks for to determine the readiness of components for work after restart,
allows to horizontally scale all cluster components just by changing replicaCount field.
Here is an example of a VMCluster resource with HA features:
Also, you can specify imagePullSecrets if you are pulling images from private repo,
but imagePullSecrets is global setting for all VMCluster specification:
If these parameters are not specified, then,
by default all VMCluster pods have resource requests and limits from the default values of the following operator parameters:
VM_VMCLUSTERDEFAULT_VMSTORAGEDEFAULT_RESOURCE_LIMIT_MEM - default memory limit for VMCluster/vmstorage pods,
VM_VMCLUSTERDEFAULT_VMSTORAGEDEFAULT_RESOURCE_LIMIT_CPU - default memory limit for VMCluster/vmstorage pods,
VM_VMCLUSTERDEFAULT_VMSTORAGEDEFAULT_RESOURCE_REQUEST_MEM - default memory limit for VMCluster/vmstorage pods,
VM_VMCLUSTERDEFAULT_VMSTORAGEDEFAULT_RESOURCE_REQUEST_CPU - default memory limit for VMCluster/vmstorage pods,
VM_VMCLUSTERDEFAULT_VMSELECTDEFAULT_RESOURCE_LIMIT_MEM - default memory limit for VMCluster/vmselect pods,
VM_VMCLUSTERDEFAULT_VMSELECTDEFAULT_RESOURCE_LIMIT_CPU - default memory limit for VMCluster/vmselect pods,
VM_VMCLUSTERDEFAULT_VMSELECTDEFAULT_RESOURCE_REQUEST_MEM - default memory limit for VMCluster/vmselect pods,
VM_VMCLUSTERDEFAULT_VMSELECTDEFAULT_RESOURCE_REQUEST_CPU - default memory limit for VMCluster/vmselect pods,
VM_VMCLUSTERDEFAULT_VMINSERTDEFAULT_RESOURCE_LIMIT_MEM - default memory limit for VMCluster/vmselect pods,
VM_VMCLUSTERDEFAULT_VMINSERTDEFAULT_RESOURCE_LIMIT_CPU - default memory limit for VMCluster/vmselect pods,
VM_VMCLUSTERDEFAULT_VMINSERTDEFAULT_RESOURCE_REQUEST_MEM - default memory limit for VMCluster/vmselect pods,
VM_VMCLUSTERDEFAULT_VMINSERTDEFAULT_RESOURCE_REQUEST_CPU - default memory limit for VMCluster/vmselect pods.
These default parameters will be used if:
VM_VMCLUSTERDEFAULT_USEDEFAULTRESOURCES is set to true (default value),
VMCluster/* CR doesn’t have resources field in spec section.
Field resources in VMCluster/* spec have higher priority than operator parameters.
If you set VM_VMCLUSTERDEFAULT_USEDEFAULTRESOURCES to false and don’t specify resources in VMCluster/* CRD,
then VMCluste/*r pods will be created without resource requests and limits.
Also, you can specify requests without limits - in this case default values for limits will not be used.
For using Enterprise version of vmcluster
you need to change version of VMCluster to version with -enterprise suffix using Version management.
All the enterprise apps require -eula command-line flag to be passed to them.
This flag acknowledges that your usage fits one of the cases listed on this page.
So you can use extraArgs for passing this flag to VMCluster.
apiVersion:operator.victoriametrics.com/v1beta1kind:VMClustermetadata:name:vmcluster-ent-examplespec:vmselect:# enabling enterprise features for vmselectimage:# enterprise version of vmselecttag:v1.93.5-enterprise-clusterextraArgs:# should be true and means that you have the legal right to run a vmselect enterprise# that can either be a signed contract or an email with confirmation to run the service in a trial period# https://victoriametrics.com/legal/esa/eula:true# using enterprise features: Downsampling# more details about downsampling you can read on https://docs.victoriametrics.com/Cluster-VictoriaMetrics#downsamplingdownsampling.period:30d:5m,180d:1h,1y:6h,2y:1dvmstorage:# enabling enterprise features for vmstorageimage:# enterprise version of vmstoragetag:v1.93.5-enterprise-clusterextraArgs:# should be true and means that you have the legal right to run a vmstorage enterprise# that can either be a signed contract or an email with confirmation to run the service in a trial period# https://victoriametrics.com/legal/esa/eula:true# using enterprise features: Downsampling# more details about downsampling you can read on https://docs.victoriametrics.com/Cluster-VictoriaMetrics#downsamplingdownsampling.period:30d:5m,180d:1h,1y:6h,2y:1d# ...other fields...
apiVersion:operator.victoriametrics.com/v1beta1kind:VMClustermetadata:name:vmcluster-ent-examplespec:vmstorage:# enabling enterprise features for vmstorageimage:# enterprise version of vmstoragetag:v1.93.5-enterprise-clusterextraArgs:# should be true and means that you have the legal right to run a vmstorage enterprise# that can either be a signed contract or an email with confirmation to run the service in a trial period# https://victoriametrics.com/legal/esa/eula:true# using enterprise features: Retention filters# more details about retention filters you can read on https://docs.victoriametrics.com/Cluster-VictoriaMetrics#retention-filtersretentionFilter:'{vm_account_id="5",env="dev"}:5d,{vm_account_id="5",env="prod"}:5y'# ...other fields...
apiVersion:operator.victoriametrics.com/v1beta1kind:VMClustermetadata:name:vmcluster-ent-examplespec:vmselect:# enabling enterprise features for vmselectimage:# enterprise version of vmselecttag:v1.93.5-enterprise-clusterextraArgs:# should be true and means that you have the legal right to run a vmselect enterprise# that can either be a signed contract or an email with confirmation to run the service in a trial period# https://victoriametrics.com/legal/esa/eula:truevminsert:# enabling enterprise features for vminsertimage:# enterprise version of vminserttag:v1.93.5-enterprise-clusterextraArgs:# should be true and means that you have the legal right to run a vminsert enterprise# that can either be a signed contract or an email with confirmation to run the service in a trial period# https://victoriametrics.com/legal/esa/eula:truevmstorage:# enabling enterprise features for vmstorageimage:# enterprise version of vmstoragetag:v1.93.5-enterprise-clusterextraArgs:# should be true and means that you have the legal right to run a vmstorage enterprise# that can either be a signed contract or an email with confirmation to run the service in a trial period# https://victoriametrics.com/legal/esa/eula:true# ...other fields...
You can pass mTLS protection
flags to VMCluster/vmstorage, VMCluster/vmselect and VMCluster/vminsert with extraArgs and mount secret files
with extraVolumes and extraVolumeMounts fields.
apiVersion:operator.victoriametrics.com/v1beta1kind:VMClustermetadata:name:vmcluster-ent-examplespec:vmselect:# enabling enterprise features for vmselectimage:# enterprise version of vmselecttag:v1.93.5-enterprise-clusterextraArgs:# should be true and means that you have the legal right to run a vmselect enterprise# that can either be a signed contract or an email with confirmation to run the service in a trial period# https://victoriametrics.com/legal/esa/eula:true# using enterprise features: mTLS protection# more details about mTLS protection you can read on https://docs.victoriametrics.com/Cluster-VictoriaMetrics#mtls-protectioncluster.tls:truecluster.tlsCAFile:/etc/mtls/ca.crtcluster.tlsCertFile:/etc/mtls/vmselect.crtcluster.tlsKeyFile:/etc/mtls/vmselect.keyextraVolumes:- name:mtlssecret:secretName:mtlsextraVolumeMounts:- name:mtlsmountPath:/etc/mtlsvminsert:# enabling enterprise features for vminsertimage:# enterprise version of vminserttag:v1.93.5-enterprise-clusterextraArgs:# should be true and means that you have the legal right to run a vminsert enterprise# that can either be a signed contract or an email with confirmation to run the service in a trial period# https://victoriametrics.com/legal/esa/eula:true# using enterprise features: mTLS protection# more details about mTLS protection you can read on https://docs.victoriametrics.com/Cluster-VictoriaMetrics#mtls-protectioncluster.tls:truecluster.tlsCAFile:/etc/mtls/ca.crtcluster.tlsCertFile:/etc/mtls/vminsert.crtcluster.tlsKeyFile:/etc/mtls/vminsert.keyextraVolumes:- name:mtlssecret:secretName:mtlsextraVolumeMounts:- name:mtlsmountPath:/etc/mtlsvmstorage:# enabling enterprise features for vmstorageimage:# enterprise version of vmstoragetag:v1.93.5-enterprise-clusterenv:- name:PODvalueFrom:fieldRef:fieldPath:metadata.nameextraArgs:# should be true and means that you have the legal right to run a vmstorage enterprise# that can either be a signed contract or an email with confirmation to run the service in a trial period# https://victoriametrics.com/legal/esa/eula:true# using enterprise features: mTLS protection# more details about mTLS protection you can read on https://docs.victoriametrics.com/Cluster-VictoriaMetrics#mtls-protectioncluster.tls:truecluster.tlsCAFile:/etc/mtls/ca.crtcluster.tlsCertFile:/etc/mtls/$(POD).crtcluster.tlsKeyFile:/etc/mtls/$(POD).keyextraVolumes:- name:mtlssecret:secretName:mtlsextraVolumeMounts:- name:mtlsmountPath:/etc/mtls# ...other fields...---apiVersion:v1kind:Secretmetadata:name:mtlsnamespace:defaultstringData:ca.crt:| -----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----mtls-vmstorage-0.crt:| -----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----mtls-vmstorage-0.key:| -----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----mtls-vmstorage-1.crt:| -----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----mtls-vmstorage-1.key:| -----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----vminsert.crt:| -----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----vminsert.key:| -----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----vmselect.crt:| -----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----vmselect.key:| -----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----
Example commands for generating certificates you can read
on this page.
You can check vmbackupmanager documentation for backup automation.
It contains a description of the service and its features. This section covers vmbackumanager integration in vmoperator.
VMCluster has built-in backup configuration, it uses vmbackupmanager - proprietary tool for backups.
It supports incremental backups (hourly, daily, weekly, monthly) with popular object storages (aws s3, google cloud storage).
Here is a complete example for backup configuration:
apiVersion:operator.victoriametrics.com/v1beta1kind:VMClustermetadata:name:vmcluster-ent-examplespec:vmstorage:vmBackup:# this feature is only available in Victoriametrics Enterprise# more details about backup automation you can read on https://docs.victoriametrics.com/vmbackupmanagerdestination:"s3://your_bucket/folder"# Read the object storage credentials from a secretcredentialsSecret:name:remote-storage-keyskey:credentials# customS3Endpoint: 'https://s3.example.com' # uncomment and adjust if you using s3 compatible storage instead of AWS s3# uncomment and adjust to fit your backup schedule# disableHourly: false# disableDaily: false# disableWeekly: false# disableMonthly: false# ...other fields...---apiVersion:v1kind:Secretmetadata:name:remote-storage-keystype:OpaquestringData:credentials:|- [default]
aws_access_key_id = your_access_key_id
aws_secret_access_key = your_secret_access_key
NOTE: for cluster version operator adds suffix for destination: "s3://your_bucket/folder", it becomes "s3://your_bucket/folder/$(POD_NAME)".
It’s needed to make consistent backups for each storage node.
You can read more about backup configuration options and mechanics here
Possible configuration options for backup crd can be found at link
Using VMBackupmanager for restoring backups in Kubernetes environment is described here.