apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: vmcluster-storage
provisioner: diskplugin.csi.alibabacloud.com
parameters:
  fsType: ext4
  type: cloud_essd
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
---
apiVersion: v1
kind: ServiceAccount
metadata:
  annotations:
    ram.aliyuncs.com/role: TMPL_VMCLUSTER_ROLE
  name: vmcluster-vmcluster
  namespace: observability
---
apiVersion: operator.victoriametrics.com/v1beta1
kind: VMCluster
metadata:
  name: vmcluster
  namespace: observability
spec:
  replicationFactor: 2
  retentionPeriod: "1"
  vminsert:
    extraArgs:
      maxLabelsPerTimeseries: "100"
      maxConcurrentInserts: "8"
      maxLabelValueLen: "16384"
    hpa:
      minReplicas: 2
      maxReplicas: 4
      metrics:
      - type: Resource
        resource:
          name: cpu
          target:
            type: Utilization
            averageUtilization: 80
      - type: Resource
        resource:
          name: memory
          target:
            type: Utilization
            averageUtilization: 90
      behaviour:
        scaleUp:
          stabilizationWindowSeconds: 60
        scaleDown:
          stabilizationWindowSeconds: 600
          # scale down at the rate of 1 pod per 5 minutes.
          policies:
          - type: Pods
            value: 1
            periodSeconds: 300
    affinity:
      podAntiAffinity:
        preferredDuringSchedulingIgnoredDuringExecution:
        - podAffinityTerm:
            labelSelector:
              matchExpressions:
              - key: app.kubernetes.io/name
                operator: In
                values:
                - vminsert
            topologyKey: kubernetes.io/hostname
          weight: 100
    image:
      repository: TMPL_IMAGE_REGISTRY/victoriametrics/vminsert
      tag: v1.122.2-cluster
    podMetadata:
      labels:
        owner: infra
    replicaCount: 2
    resources:
      requests:
        cpu: "0.05"
        memory: 64Mi
      limits:
        cpu: "0.2"
        memory: 256Mi
    nodeSelector:
      node_type: worker
  vmselect:
    persistentVolumeClaimRetentionPolicy:
      whenDeleted: Delete
      whenScaled: Delete
    affinity:
      podAntiAffinity:
        preferredDuringSchedulingIgnoredDuringExecution:
        - podAffinityTerm:
            labelSelector:
              matchExpressions:
              - key: app.kubernetes.io/name
                operator: In
                values:
                - vmselect
            topologyKey: kubernetes.io/hostname
          weight: 100
    hpa:
      minReplicas: 2
      maxReplicas: 4
      metrics:
      - type: Resource
        resource:
          name: cpu
          target:
            type: Utilization
            averageUtilization: 90
      - type: Resource
        resource:
          name: memory
          target:
            type: Utilization
            averageUtilization: 90
      behaviour:
        scaleUp:
          stabilizationWindowSeconds: 60
        scaleDown:
          stabilizationWindowSeconds: 600
          # scale down at the rate of 1 pod per 5 minutes.
          policies:
          - type: Pods
            value: 1
            periodSeconds: 300
    cacheMountPath: /select-cache
    extraArgs:
      search.skipSlowReplicas: "true"
      search.maxConcurrentRequests: "10"
      search.logQueryMemoryUsage: "500MiB"
    image:
      repository: TMPL_IMAGE_REGISTRY/victoriametrics/vmselect
      tag: v1.122.2-cluster
    podMetadata:
      labels:
        owner: infra
    replicaCount: 2
    resources:
      requests:
        cpu: "0.05"
        memory: 64Mi
      limits:
        cpu: "0.2"
        memory: 256Mi
    storage:
      volumeClaimTemplate:
        metadata: {}
        spec:
          resources:
            requests:
              storage: 20Gi
        status: {}
    nodeSelector:
      node_type: worker
  vmstorage:
    topologySpreadConstraints:
    - maxSkew: 1
      topologyKey: kubernetes.io/hostname
      whenUnsatisfiable: ScheduleAnyway
      labelSelector:
        matchLabels:
          app.kubernetes.io/name: vmstorage
    affinity:
      podAntiAffinity:
        preferredDuringSchedulingIgnoredDuringExecution:
        - podAffinityTerm:
            labelSelector:
              matchExpressions:
              - key: app.kubernetes.io/name
                operator: In
                values:
                - vmstorage
            topologyKey: kubernetes.io/hostname
          weight: 50
    image:
      repository: TMPL_IMAGE_REGISTRY/victoriametrics/vmstorage
      tag: v1.122.2-cluster
    podMetadata:
      labels:
        owner: infra
    replicaCount: 2
    resources:
      requests:
        cpu: "0.02"
        memory: 256Mi
      limits:
        cpu: "0.2"
        memory: 512Mi
    storage:
      volumeClaimTemplate:
        metadata: {}
        spec:
          storageClassName: vmcluster-storage
          resources:
            requests:
              storage: 50Gi
        status: {}
    extraArgs:
      storage.vminsertConnsShutdownDuration: "90s"
    terminationGracePeriodSeconds: 120
    storageDataPath: /vm-data
    nodeSelector:
      node_type: worker
    containers:
      - name: vmbackuper
        image: TMPL_IMAGE_REGISTRY/vmbackup:v3
        imagePullPolicy: Always
        serviceAccount: vmcluster-vmcluster
        serviceAccountName: vmcluster-vmcluster
        volumeMounts:
          - mountPath: /vm-data
            name: vmstorage-db
        resources:
          requests:
            cpu: "0.05"
            memory: 20Mi
          limits:
            cpu: "0.5"
            memory: 256Mi
        command:
          - /usr/local/bin/entrypoint.sh
        args:
          - -storageDataPath=/vm-data
          - -snapshot.createURL=http://localhost:8482/snapshot/create
          - -dst=s3://TMPL_VMCLUSTER_BUCKET_NAME/1/vmcluster/${MY_POD_NAME}
          - -maxBytesPerSecond=52428800
          - -customS3Endpoint=TMPL_CUSTOM_S3_ENDPOINT
        env:
          - name: MY_POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: AWS_ACCESS_KEY_ID
            valueFrom:
              secretKeyRef:
                key: AWS_ACCESS_KEY_ID
                name: o11y-regional-ram-credentials
          - name: AWS_SECRET_ACCESS_KEY
            valueFrom:
              secretKeyRef:
                key: AWS_SECRET_ACCESS_KEY
                name: o11y-regional-ram-credentials
---
apiVersion: operator.victoriametrics.com/v1beta1
kind: VMAlert
metadata:
  name: vmalert-shared
  namespace: observability
spec:
  containers:
    - name: config-reloader
      resources:
        limits:
          cpu: 10m
        requests:
          cpu: 10m
  datasource:
    url: http://vmselect-vmcluster.observability.svc.cluster.local:8481/select/multitenant/prometheus
  image:
    repository: TMPL_IMAGE_REGISTRY/victoriametrics/vmalert
    tag: v1.122.2-cluster-hotfix-20260305
  livenessProbe:
    initialDelaySeconds: 30
  notifiers:
    - url: http://alertmanager-operated.default.svc.cluster.local:9093
  readinessProbe:
    initialDelaySeconds: 30
  remoteRead:
    url: http://vmselect-vmcluster.observability.svc.cluster.local:8481/select/multitenant/prometheus
  remoteWrite:
    url: http://vminsert-vmcluster.observability.svc.cluster.local:8480/insert/multitenant/prometheus
    maxBatchSize: 5000
  resources:
    limits:
      cpu: 30m
      memory: 150Mi
    requests:
      cpu: 10m
      memory: 50Mi
  ruleNamespaceSelector:
    matchLabels:
      observability.pingcap.com/rule-multi-tenancy: "true"
  ruleSelector:
    matchExpressions:
    - key: observability.pingcap.com/rule-multi-tenancy
      operator: In
      values:
      - "true"
    - key: observability.pingcap.com/cluster-paused
      operator: NotIn
      values:
      - "true"
    - key: observability.pingcap.com/applicationID
      operator: NotIn
      values:
      - base
      - seed
