Skip to content
lorebow

Step 3 of 9, about 2 min

Set up storage

Make the redis-storage StorageClass with Longhorn, NFS, local-path or volumes made by hand.

Every option below ends with a StorageClass named redis-storage, so every later step is the same whichever you pick. Redis needs ReadWriteOnce volumes: one disk per pod. How each one behaves when a pod moves is drawn in the post.

#Pick where the data lives

Longhorn gives each pod a network disk that follows it to any node, and keeps copies of each disk on other nodes. Every node needs open-iscsi installed and iscsid running first (apt install open-iscsi on Debian and Ubuntu, then systemctl enable --now iscsid). Longhorn 1.13 needs Kubernetes 1.34 or later. It runs on real or virtual machines, not on kind.

bash
helm repo add longhorn https://charts.longhorn.io
helm repo update
helm install longhorn longhorn/longhorn --version 1.13.0 \
  --namespace longhorn-system --create-namespace
kubectl -n longhorn-system get pods --watch

Wait until every pod is Running, then add a class for Redis. Redis already keeps copies on its replicas, so two Longhorn copies per disk is enough, and best-effort locality keeps one of them on the node the pod runs on.

storageclass.yamlyaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: redis-storage
provisioner: driver.longhorn.io
allowVolumeExpansion: true
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
parameters:
  numberOfReplicas: "2"
  dataLocality: best-effort
  staleReplicaTimeout: "30"
  fsType: ext4

#Apply it and check

Apply the class and check it:

bash
kubectl apply -f storageclass.yaml
kubectl get storageclass redis-storage