I have dynamic PersistentVolume
provisioning using PersistentVolumeClaim
.
I would like to keep the PV after the pod is done. So I would like to have what persistentVolumeReclaimPolicy: Reclaim
does.
However, that is applicable to PersistentVolume
, not PersistentVolumeClaim
(AFAIK).
How can I change this behavior for dynamically provisioned PV's?
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ .Release.Name }}-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: gp2
resources:
requests:
storage: 6Gi
---
kind: Pod
apiVersion: v1
metadata:
name: "{{ .Release.Name }}-gatling-test"
spec:
restartPolicy: Never
containers:
- name: {{ .Release.Name }}-gatling-test
image: ".../services-api-mvn-builder:latest"
command: ["sh", "-c", 'mvn -B gatling:test -pl csa-testing -DCSA_SERVER={{ template "project.fullname" . }} -DCSA_PORT={{ .Values.service.appPort }}']
volumeMounts:
- name: "{{ .Release.Name }}-test-res"
mountPath: "/tmp/testResults"
volumes:
- name: "{{ .Release.Name }}-test-res"
persistentVolumeClaim:
claimName: "{{ .Release.Name }}-pvc"
#persistentVolumeReclaimPolicy: Retain ???
Reclaiming a persistent volume manuallyDelete the PV. The associated storage asset in the external infrastructure, such as an AWS EBS, GCE PD, Azure Disk, or Cinder volume, still exists after the PV is deleted. Clean up the data on the associated storage asset. Delete the associated storage asset.
you can config it in pv.yaml or storageclass.yaml or take a patch to exit pv
pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv0003
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
storageClassName: slow
mountOptions:
- hard
- nfsvers=4.1
nfs:
path: /tmp
server: 172.17.0.2
storageclass.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: gp2-retain
annotations:
provisioner: kubernetes.io/aws-ebs
parameters:
type: gp2
fsType: ext4
reclaimPolicy: Retain
take a patch
kubectl patch pv <your-pv-name> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With