Reputation: 1709
I have a persistent volume defined as
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ghost-cms-content
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: do-block-storage
and a deployment defined as
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: ghost-cms
spec:
replicas: 4
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
selector:
matchLabels:
app: ghost-cms
tier: frontend
template:
metadata:
labels:
app: ghost-cms
tier: frontend
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/region
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: ghost-cms
tier: frontend
containers:
- name: ghost-cms
image: ghost:4.6-alpine
imagePullPolicy: Always
ports:
- containerPort: 2368
volumeMounts:
- mountPath: /var/lib/ghost/content
name: content
env:
- name: url
value: https://ghost.site
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
volumes:
- name: content
persistentVolumeClaim:
claimName: ghost-cms-content
but each replica appears to have a unique volume that is not shared with the rest of the replicas. For instance, when I create a text file inside /var/lib/ghost/content
in one of the pods, I don't see it in the volume of the other pods. What am I doing wrong?
Upvotes: 3
Views: 2454
Reputation: 30083
PVC with permission
accessModes:
- ReadWriteOnce
Each pod will get the one volume or PVC, as it's readwrite once.
If you want to keep shared volume across replicas you can use the NFS with accessMode ReadWriteMany
accessModes:
- ReadWriteMany
Read more at : https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes
You can also use Minio, GlusterFS to creeat the NFS or any managed service like GCP filestore providing NFS and attach that to POD.
GKE example : https://medium.com/@Sushil_Kumar/readwritemany-persistent-volumes-in-google-kubernetes-engine-a0b93e203180
Upvotes: 4