Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to utilize filestore as persistent volume in statefulset gke

I am trying to deploy 2 Replicas of Elasticsearch pods on gke using Statefulset with filestore as a volume , but after researching for few hours in every documentation It is suggested to provision persistent disk for Statefulset which it don't want , I want to utilize my filestore and store the data's of both replicas of Elasticsearch 

so what changes should I do to achieve this:-

here is the pv file

apiVersion: v1
kind: PersistentVolume
metadata:
 name: elasticsearch-pv
 namespace: elk
spec:
 capacity:
   storage: 10Gi
 accessModes:
 - ReadWriteOnce
 nfs:
   path: /filestore_vol1/elastic-gke/
   server: 10.x.x.122

here is the deployment file :- 
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: elasticsearch-cluster
  namespace: elk
spec:
  serviceName: elasticsearch
  replicas: 2
  selector:
    matchLabels:
      app: elasticsearch
  template:
    metadata:
      labels:
        app: elasticsearch
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: app-elk
                operator: In
                values:
                - "elastic-tomcat"
      containers:
      - name: elasticsearch
        image: elasticsearch:7.17.5
        imagePullPolicy: Always
        resources:
            limits:
              cpu: 1000m
            requests:
              cpu: 200m
        ports:
        - containerPort: 9200
          name: rest
          protocol: TCP
        - containerPort: 9300
          name: inter-node
          protocol: TCP
        volumeMounts:
        - name: data
          mountPath: /usr/share/elasticsearch/data
        env:
          - name: cluster.name
            value: elasticsearch-cluster
          - name: node.name
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: discovery.seed_hosts
            value: "elasticsearch-cluster-0.elasticsearch,elasticsearch-cluster-1.elasticsearch"
          - name: cluster.initial_master_nodes
            value: "elasticsearch-cluster-0"
          - name: ES_JAVA_OPTS
            value: "-Xms512m -Xmx512m"
          - name: network.host
            value: "0.0.0.0"
      initContainers:
      - name: fix-permissions
        image: busybox
        command: ["sh", "-c", "chown -R 1000:1000 /usr/share/elasticsearch/data"]
        securityContext:
          privileged: true
        volumeMounts:
        - name: data
          mountPath: /usr/share/elasticsearch/data
      - name: increase-vm-max-map
        image: busybox
        command: ["sysctl", "-w", "vm.max_map_count=262144"]
        securityContext:
          privileged: true
      - name: increase-fd-ulimit
        image: busybox
        command: ["sh", "-c", "ulimit -n 65536"]
        securityContext:
          privileged: true
  volumeClaimTemplates:
  - metadata:
      name: data
      labels:
        app: elasticsearch
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: ""
      volumeName: elasticsearch-pv
      resources:
        requests:
          storage: 3Gi

 

0 4 1,112
4 REPLIES 4

Have you checked out https://cloud.google.com/filestore/docs/csi-driver?  It shows you how to use existing Filestore volumes and/or dynamically provision new ones.

There is no example for kind:statefulset the only example given here for kind:deployment also in the examples their is no sign of  volumeClaimTemplates 

 

A `volumeClaimTemplate` is basically the same format as a PVC.    In your example

volumeClaimTemplates:
  - metadata:
      name: data
      labels:
        app: elasticsearch
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: ""
      volumeName: elasticsearch-pv
      resources:
        requests:
          storage: 3Gi
 
you just need to fill in the `storageClassName` using one of the pre-installed ones or creating your own.

can you check if my pv yaml  is correct or do I need to add some thing more:-

 

apiVersionv1
kindPersistentVolume
metadata:
 nameelasticsearch-pv
 namespaceelk
spec:
 capacity:
   storage10Gi
 accessModes:
 - ReadWriteOnce
 nfs:
   path/filestore_vol1/elastic-gke/
   server10.x.x.122
Top Labels in this Space