How to change PVC size for statefulset with helm chart for new releases and preserve value for existing releases

2.5k Views Asked by At

It is known that PVC resize for existing statefulsets is not possible yet https://github.com/kubernetes/kubernetes/issues/68737

Now, I have a helm chart with a statefulset and a PVC with 1GB size. When upgrading existing releases, I want to keep the existing value for the volume size, 1GB.

When installing new releases, I want to change the default to, let's say, 10GB.

How can I achieve this with the same chart, and only with default values (without providing custom values at install time) ?

I tried with:

  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
{{- if .Release.IsInstall }}
          storage: {{ .Values.storage.size }}
{{- end }}

which works for scratch installs, but then for an upgrade, the "storage" attribute is removed by helm and I am back to the same error:

Error: StatefulSet.apps "test" is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden

Is there a way to get/preserve the previous applied value from inside the helm template ?

Note that I'm on helm v2.

Scenario:

  • I have a chart with versions: 1.0.0, 1.0.1
  • For version 1.0.0 .Values.storage.size is 1GB
  • For version 1.0.1 .Values.storage.size is 10GB
  • I have an existing release, A, with chart version 1.0.0, so volume size 1GB
  • With only default values defined in values.yaml, I want to be able to:
    • upgrade release A from chart version 1.0.0 to 1.0.1 while preserving the volume size (1GB)
    • install from scratch release B, with chart version 1.0.1, with volume size 10
0

There are 0 best solutions below