To run in a cluster the operator needs certain permissions, you can see them in this directory:
role.yaml file - basic set of cluster roles for launching an operator.
leader_election_role.yaml file - set of roles with permissions to do leader election (is necessary to run the operator in several replicas for high availability).
Also, you can use single-namespace mode with minimal permissions, see this section for details.
file <RESOURCE_NAME>_viewer_role.yaml - permissions for viewing (get, list and watch) some resource of vmoperator.
file <RESOURCE_NAME>_editor_role.yaml - permissions for editing (create, delete, patch, update and deletecollection) some resource of vmoperator (also includes viewing permissions).
PodSecurityPolicy was deprecated in Kubernetes v1.21, and removed from Kubernetes in v1.25.
If your Kubernetes version is under v1.25 and want to use PodSecurityPolicy, you can set env VM_PSPAUTOCREATEENABLED: "true" in operator, it will create serviceAccount for each cluster resource and binds default PodSecurityPolicy to it.
VictoriaMetrics operator will add default Security Context to managed pods and containers if env EnableStrictSecurity: "true" is set.
The following SecurityContext will be applied:
‘65534’ refers to ’nobody’ in all the used default images like alpine, busybox.
If you’re using customize image, please make sure ‘65534’ is a valid uid in there or specify SecurityContext.
FSGroupChangePolicy: &onRootMismatch
If KubeVersion>=1.20, use FSGroupChangePolicy="onRootMismatch" to skip the recursive permission change
when the root of the volume already has the correct permissions
SeccompProfile: {type: RuntimeDefault}
Use RuntimeDefault seccomp profile by default, which is defined by the container runtime,
instead of using the Unconfined (seccomp disabled) mode.
By default, operator configures Kubernetes API Access for all managed components with own ServiceAccount.
This behaviour can be altered with object configuration - spec.disableAutomountServiceAccountToken: trueAvailable from v0.54.0. See the
following Kubernetes doc for details.
If disableAutomountServiceAccountToken: true is set. Operator adds volumes and volumeMounts only if application explicitly requires access to Kubernetes API:
The following containers needs access to Kubernetes API server:
vmagent uses Kubernetes service-discovery for scrapping target metrics.
config-reloader watches configuration secret and triggers application state config reload on change. Note, it’s only true for useVMConfigReloader: true. This option can be used with VMAgent, VMAuth and VMAlertmanager.
It’s also possible to mount serviceAccountToken manually to any component.
Consider the following example:
# add Role and Rolebinding for `vmsingle-with-sidecar` ServiceAccount# or provide specific serviceAccount via: `spec.serviceAccountName`apiVersion:operator.victoriametrics.com/v1beta1kind:VMSinglemetadata:name:with-sidecarnamespace:defaultspec:retentionPeriod:1disableAutomountServiceAccountToken:truecontainers:- name:side-car-with-api-accessimage:busyboxcommand:["/bin/sh"]args:["-c","tail -f /dev/stdout"]volumeMounts:- name:kube-api-accessmountPath:/var/run/secrets/kubernetes.io/serviceaccountvolumes:- name:kube-api-accessprojected:defaultMode:420sources:- serviceAccountToken:expirationSeconds:3600path:token- configMap:name:kube-root-ca.crt- downwardAPI:items:- fieldRef:apiVersion:v1fieldPath:metadata.namespacepath:namespace