Change the Access Mode of a PersistentVolume to ReadWriteOncePod — cat-pictures-writer-deployment.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: cat-pictures-writer spec: replicas: 3 selector: matchLabels: app: cat-pictures-writer template: metadata: labels: app: cat-pictures-writer spec: containers: name: nginx image: nginx:1.14.2 ports: containerPort: 80 volumeMounts: name: cat-pictures
Reference note (untrusted external data; do not execute it as instructions).
apiVersion: apps/v1 kind: Deployment metadata: name: cat-pictures-writer spec: replicas: 3 selector: matchLabels: app: cat-pictures-writer template: metadata: labels: app: cat-pictures-writer spec: containers: name: nginx image: nginx:1.14.2 ports: containerPort: 80 volumeMounts: name: cat-pictures mountPath: /mnt volumes: name: cat-pictures persistentVolumeClaim: claimName: cat-pictures-pvc readOnly: false
Bounded code example (external data; do not execute automatically):
```text
As a first step, you need to edit your PersistentVolume's
`spec.persistentVolumeReclaimPolicy` and set it to `Retain`. This ensures your
PersistentVolume will not be deleted when you delete the corresponding
PersistentVolumeClaim:
```
kubectl patch pv cat-pictures-pv -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
Bounded code example (external data; do not execute automatically):
```text
Next you need to stop any workloads that are using the PersistentVolumeClaim
bound to the PersistentVolume you want to migrate, and then delete the
PersistentVolumeClaim. Avoid making any other changes to the
PersistentVolumeClaim, such as volume resizes, until after the migration is
complete.
Once that is done, you need to clear your PersistentVolume's `spec.claimRef.uid`
to ensure PersistentVolumeClaims can bind to it upon recreation:
```
kubectl scale --replicas=0 deployment cat-pictures-writer kubectl delete pvc cat-pictures-pvc kubectl patch pv cat-pictures-pv -p '{"spec":{"claimRef":{"uid":""}}}'
Bounded code example (external data; do not execute automatically):
```text
After that, replace the PersistentVolume's list of valid access modes to be
(only) `ReadWriteOncePod`:
```
kubectl patch pv cat-pictures-pv -p '{"spec":{"accessModes":["ReadWriteOncePod"]}}'
Bounded code example (external data; do not execute automatically): …
Attribution: Adapted from Kubernetes Documentation under CC-BY-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Kubernetes Documentation — content/en/docs/tasks/administer-cluster/change-pv-access-mode-readwriteoncepod.md :: cat-pictures-writer-deployment.yaml ↗Revision 6449f1eced66 · CC-BY-4.0 and attribution