Iscsi as persistent storage statefulset kubernetes

7/1/2021

I have a use case where there will be telecom application running within the several pods(every pod will host some configured service for billing for specific client) and this expects the service to store the state so obvious choice is statefulset . Now the problem is I need to use iscsi as storage in the backend for these pods, Can you please point me to some reference to such use case - I am looking for Yaml for PV PVC and statefulset and how to link them . These PV PVC shall use iscsi as storage option.

-- Rakesh sood
kubernetes
kubernetes-statefulset

1 Answer

7/1/2021

Yes you are right statefulset is option however you might can also use the deployment.

You have not mentioned which cloud provider you will be using but still sharing one note : iscsi storage is not optimized with GKE cotnainer OS running K8s nodes so if you are no GCP GKE change OS or would suggest using the Ubuntu image first.

You can start the iscsi service on the Ubuntu first.

You can use the Minio or OpenEBS for the storage option also.

Sharing the details if for OpenEBS

Create GCP disks for attaching nodes as a mount or you can dynamically provision it using the YAML as per need.

apiVersion: openebs.io/v1alpha1
kind: StoragePoolClaim
metadata:
  name: disk-pool
  annotations:
    cas.openebs.io/config: |
      - name: PoolResourceRequests
        value: |-
            memory: 2Gi
      - name: PoolResourceLimits
        value: |-
            memory: 4Gi
spec:
  name: disk-pool
  type: disk
  poolSpec:
    poolType: striped
  blockDevices:
    blockDeviceList:
- blockdevice-<Number>   
- blockdevice-<Number> 
- blockdevice-<Number>  

Stoage class

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: openebs-sc-rep1
  annotations:
    openebs.io/cas-type: cstor
    cas.openebs.io/config: |
      - name: StoragePoolClaim
        value: "disk-pool"
      - name: ReplicaCount
        value: "1"
provisioner: openebs.io/provisioner-iscsi

Application workload

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: k8s.gcr.io/nginx-slim:0.8
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates: 
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi
      storageClassName: openebs-sc-rep1

if you are on AWS EBS using the iscsi. For testing you can also checkout

https://cloud.ibm.com/catalog/content/minio

Few links :

-- Harsh Manvar
Source: StackOverflow