How to mount cassandra data location to azure file share using stateful set kubernetes

4/2/2019

I am setting up 3 node Cassandra cluster on Azure using Statefull set Kubernetes and not able to mount data location in azure file share.

I am able to do using default kubenetes storage but not with Azurefile share option.

I have tried the following steps given below, finding difficulty in volumeClaimTemplates

apiVersion: "apps/v1"
kind: StatefulSet
metadata:
  name: cassandra
  labels:
    app: cassandra
spec:
  serviceName: cassandra
  replicas: 3
  selector:
    matchLabels:
      app: cassandra
  template:
    metadata:
      labels:
        app: cassandra
    spec:
      containers:
        - name: cassandra
          image: cassandra
          imagePullPolicy: Always
          ports:
            - containerPort: 7000
              name: intra-node
            - containerPort: 7001
              name: tls-intra-node
            - containerPort: 7199
              name: jmx
            - containerPort: 9042
              name: cql
          env:
            - name: CASSANDRA_SEEDS
              value: cassandra-0.cassandra.default.svc.cluster.local
            - name: MAX_HEAP_SIZE
              value: 256M
            - name: HEAP_NEWSIZE
              value: 100M
            - name: CASSANDRA_CLUSTER_NAME
              value: "Cassandra"
            - name: CASSANDRA_DC
              value: "DC1"
            - name: CASSANDRA_RACK
              value: "Rack1"
            - name: CASSANDRA_ENDPOINT_SNITCH
              value: GossipingPropertyFileSnitch
            - name: POD_IP
              valueFrom:
                fieldRef:
                   fieldPath: status.podIP                 
          volumeMounts:
          - mountPath: /var/lib/cassandra/data
            name: pv002
  volumeClaimTemplates:
  - metadata:
      name: pv002
    spec:
      storageClassName: default
      accessModes:
        - ReadWriteOnce
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv002
  accessModes:
  - ReadWriteOnce
  azureFile:
    secretName: storage-secret
    shareName: xxxxx
    readOnly: false
  claimRef:
    namespace: default
    name: az-files-02
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: az-files-02
spec:
  accessModes:
    - ReadWriteOnce
---
apiVersion: v1
kind: Secret
metadata:
  name: storage-secret
type: Opaque
data:
  azurestorageaccountname: xxxxx
  azurestorageaccountkey: jjbfjbsfljbafkljasfkl;jf;kjd;kjklsfdhjbsfkjbfkjbdhueueeknekneiononeojnjnjHBDEJKBJBSDJBDJ==

I should able to mount data folder of each cassandra node into azure file share.

-- suraj1287
azure
cassandra
kubernetes

1 Answer

4/3/2019

For using azure file in statefulset, I think you could following this example: https://github.com/andyzhangx/demo/blob/master/linux/azurefile/attach-stress-test/statefulset-azurefile1-2files.yaml

-- andy zhang
Source: StackOverflow