Kubernetes volume hostPath doesn't work for multiple replica

8/6/2018

I'd like to use volumes for deployments with more than one replica at the same time.

I'm using hostPath volume type now but the hostPath only works on one pod and the others can't to access to volume at the same time.

How to use all replicas to the volume at the same time?

Deployment file:

apiVersion: apps/v1 kind: Deployment metadata: name: pps-wordpress labels: app: wordpress spec: replicas: 4 selector: matchLabels: app: wordpress template: metadata: labels: app: wordpress spec: containers: - name: wordpress image: meysam001/wordpress volumeMounts: - name: aws-storage mountPath: /var/www/html ports: - containerPort: 80 volumes: - name: aws-storage hostPath: path: /mnt/s3

-- Meysam Mahmoodi
kubernetes

1 Answer

8/7/2018

With your issue, I would suggest using the storage solution from the Kubernetes foundation. It is called PersistentVolumeClaim. This resource exists independently of Pods. Data on this volume still exists during all lifecycle of Pods. It can be compared to NFS auto-mounted on the boot of Operating System.

You may find these multiple mounting options useful for satisfying all needs of your Pods ecosystem:

ReadWriteOnce - volume in read-write mode by a single node

ReadOnlyMany - volume in read-only mode by many nodes

ReadWriteMany - read-write mode for all consumers

To create 30Gi volume in ReadWriteMany mode, please deploy yaml like this:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: helloweb-disk
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 30Gi

Please note that this feature does work on cloud vendors, not evidently on private clouds.

-- d0bry
Source: StackOverflow