ReadWriteMany storage on Google Kubernetes Engine for StatefulSets

1/16/2019

I used NFS for to mount a ReadWriteMany storage on a deployment on Google Kubernetes Engine as described in the following link-

https://medium.com/platformer-blog/nfs-persistent-volumes-with-kubernetes-a-case-study-ce1ed6e2c266

However my particular use case(elasticsearch production cluster- for snapshots) requires mounting the ReadWriteMany volume on a stateful set. On using the NFS volume created previously for stateful sets, the volumes are not provisioned for the different replicas of the stateful set.

Is there any way to overcome this or any other approach I can use?

-- Ben Abey
elasticsearch
kubernetes

1 Answer

1/21/2019

The guide makes a small mistake depending on how you follow it. The [ClusterIP] defined in the persistent volume should be "nfs-server.default..." instead of "nfs-service.default...". "nfs-server" is what is used in the service definition.

Below is a very minimal setup I used for a statefulset. I deployed the first 3 files from the tutorial to create the PV & PVC, then used the below yaml in place of the busybox bonus yaml the author included. This deployed successfully. Let me know if you have troubles.

apiVersion: v1
kind: Service
metadata:
    name: stateful-service
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: thestate
---
apiVersion: apps/v1
metadata:
  name: thestate
    labels:
      app: thestate
kind: StatefulSet
spec:
  serviceName: stateful-service
  replicas: 3
  selector:
    matchLabels:
      app: thestate
  template:
    metadata:
      labels:
        app: thestate
    spec:
      containers:
      - name: nginx
        image: nginx:1.8
        volumeMounts:
          - name: my-pvc-nfs
            mountPath: /mnt
        ports:
        - containerPort: 80
          name: web
      volumes:
      - name: my-pvc-nfs
        persistentVolumeClaim:
          claimName: nfs
-- xavierc
Source: StackOverflow