VictoriaMetrics / operator

Kubernetes operator for Victoria Metrics
Apache License 2.0
429 stars 143 forks source link

support: when deleting vmcluster, the related pvc was not deleted #848

Closed hansedong closed 9 months ago

hansedong commented 9 months ago

I encountered a problem when deploying vmcluster: the PVCs automatically created by the operator were not deleted when the vmcluster was deleted.

apiVersion: operator.victoriametrics.com/v1beta1
kind: VMCluster
metadata:
  name: vmcluster-nfs
  namespace: monitor
spec:
  replicationFactor: 2
  retentionPeriod: 30d
  vmstorage:
    replicaCount: 5
    image:
      repository: victoriametrics/vmstorage
      tag: v1.96.0-cluster
      pullPolicy: Always
    storageDataPath: "/vm-data"
    affinity:
      podAntiAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchExpressions:
            - key: "app.kubernetes.io/name"
              operator: In
              values:
              - "vmstorage"
          topologyKey: "kubernetes.io/hostname"
    storage:
      volumeClaimTemplate:
        spec:
          resources:
            requests:
              storage: 500Gi
    resources:
      limits:
        cpu: "20"
        memory: 10240Mi
  vmselect:
    replicaCount: 3
    image:
      repository: victoriametrics/vmselect
      tag: v1.96.0-cluster
      pullPolicy: Always
    cacheMountPath: "/select-cache"
    affinity:
      podAntiAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchExpressions:
            - key: "app.kubernetes.io/name"
              operator: In
              values:
              - "vmselect"
          topologyKey: "kubernetes.io/hostname"
    storage:
      volumeClaimTemplate:
        spec:
          resources:
            requests:
              storage: 20Gi
    resources:
      limits:
        cpu: "8"
        memory: "4096Mi"
  vminsert:
    replicaCount: 5
    image:
      repository: victoriametrics/vmselect
      tag: v1.96.0-cluster
      pullPolicy: Always
    affinity:
      podAntiAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchExpressions:
            - key: "app.kubernetes.io/name"
              operator: In
              values:
              - "vminsert"
          topologyKey: "kubernetes.io/hostname"
    resources:
      limits:
        cpu: "8"
        memory: "4096Mi"

This issue is 100% reproducible, and I would like to know if this is by design or a bug in the operator?

f41gh7 commented 9 months ago

Hello, currently it's expected behavior. We should mention it at our docs.

I think, we can implement new k8s feature for pvc retention policy https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#persistentvolumeclaim-retention

But it's supported only by the most recent kubernetes versions.

hansedong commented 9 months ago

@f41gh7 Got it, thanks for the clarification.