Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes: how to do dynamic PersistentVolumeClaim with persistentVolumeReclaimPolicy: Reclaim

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  ???
like image 647
Ondra Žižka Avatar asked May 22 '18 00:05

Ondra Žižka


People also ask

How do you reclaim persistent volume?

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.


1 Answers

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"}}'

like image 193
will Avatar answered Sep 21 '22 08:09

will