Use ephemeral volumes in K8S cluster

9/3/2019

I have a k8s cluster created using Kube-spray. The volume provisioning is supported using Rook. I was using persistent volumes till now.

The application is deployed using the helm chart. The helm release is upgraded multiple times for the test-purposes. I want the pods to use new volume each time I upgrade the chart. I don't want the pod to use the old data after helm upgrade.

How can I accomplish this? How to use ephemeral volumes?

Already tried removing the PVs before performing the helm upgrade.

-- AnjanaDyna
kubernetes
kubernetes-rook
volume

2 Answers

9/4/2019

One trick that we could try for temporary volume is:

  1. Install the chart with emptyDir volumes instead of pv or pvc.
  2. Run the tests with that deployments. That would make changes to volume contents.
  3. Delete the pods that use emptyDir volumes. This will also remove the current volume data. The pods will be recreated automatically.
  4. Do the helm upgrade.
-- AnjanaDyna
Source: StackOverflow

9/3/2019

helm upgrade will try to keep as much of the existing infrastructure around as it can. If you already have a PersistentVolumeClaim named myapp-pvc, and you run helm upgrade, it will notice that PVC already exists, and leave it intact. I think this happens at the Helm layer, but even if Helm uploaded an identical PVC description to Kubernetes, it would still result in no change.

The blunt approach is to run helm del --purge the existing installation, wait for the PVCs to be fully cleaned up, and then helm install anew.

Another possible approach is to encode some unique or random value in the PVC name. The trick is that you need the same value to be used across all uses of it within the same chart installation, but then to be different if the chart is upgraded. You can use a combination of the chart metadata to provide this

{{- define "myapp.pvc.name" -}}
{{ .Release.Name }}-{{ .Chart.Name }}-pvc
{{- if .Values.destroyPersistentState -}}
-{{ .Release.Revision }}
{{- end -}}
{{- end -}}
-- David Maze
Source: StackOverflow