Modifying the persistent volume name for the claim created

10/31/2019

I have a persistent volume claim created and a random persistent volume name is bound to the claim. Can the persistent volume name be modified, if so whats the process?

Tried the following: Open the dashboard of k8, edit the pvc. but it throws the below error: spec: Forbidden: is immutable after creation except resources.requests for bound claims

kind: PersistentVolume
apiVersion: v1
metadata:
  name: task-pv-volume
  namespace: xxxxxxxx
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: task-pv-claim
  namespace: xxxxx
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  storageClassName: manual
  volumeMode: Filesystem

NAME               STATUS   VOLUME           CAPACITY   ACCESS MODES   STORAGECLASS     AGE
task-pv-claim      Bound    task-pv-volume   10Gi       RWX            manual           16m
-- Sreepada Jayanthi
kubernetes

1 Answer

10/31/2019

Once the persistent volume is bound to pvc you cant change persistent volume name. Delete the pvc and pv and recreate the pv with the required name.

Alternatively, you can pre-bind the pv with a specific pvc. Follow the below steps

  1. Create the pv and bind it with specific pvc
  2. Create pvc from the name given in pv
  3. The pv and pvc should be bound together
-- P Ekambaram
Source: StackOverflow