Managing Kubernetes Storage on Debian: A Structured Approach
Kubernetes storage management on Debian involves configuring persistent storage solutions, defining storage abstractions, and ensuring high availability for stateful applications. Below is a step-by-step guide covering essential components and common storage options.
Before configuring storage, ensure your Debian nodes meet the following requirements:
kubeadm (initialize with sudo kubeadm init --pod-network-cidr=10.244.0.0/16).kubectl apply -f https://docs.projectcalico.org/v3.25/manifests/calico.yaml) or Flannel (kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml) for Pod communication.containerd (default for newer Kubernetes versions) with optimized configuration (load overlay and br_netfilter modules, set net.bridge.bridge-nf-call-iptables=1 via sysctl).Two key abstractions manage storage in Kubernetes:
StorageClass.NFS is a simple shared storage solution for stateful applications (e.g., WordPress databases).
sudo apt install nfs-kernel-server -y
sudo mkdir -p /data/nfs-server
echo "/data/nfs-server *(rw,async,no_subtree_check)" | sudo tee -a /etc/exports
sudo systemctl start nfs-kernel-server && sudo systemctl enable nfs-kernel-server
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteMany # Allows multiple Pods to write
nfs:
server: <NFS_SERVER_IP>
path: /data/nfs-server
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
kubectl apply -f <filename>.yaml.Ceph provides scalable block, file, and object storage. Use Rook to simplify deployment on Kubernetes.
ceph-common (sudo apt install ceph-common -y).kubectl apply -f https://raw.githubusercontent.com/rook/rook/release-1.13/cluster/examples/kubernetes/ceph/operator.yaml
kubectl apply -f https://raw.githubusercontent.com/rook/rook/release-1.13/cluster/examples/kubernetes/ceph/cluster.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: rook-ceph-block
provisioner: rook-ceph.rbd.csi.ceph.com
parameters:
clusterID: <CLUSTER_ID> # From Rook dashboard
pool: replicapool
imageFeatures: layering
csi.storage.k8s.io/provisioner-secret-name: rook-csi-rbd-provisioner-secret
csi.storage.k8s.io/provisioner-secret-namespace: rook-ceph
csi.storage.k8s.io/node-stage-secret-name: rook-csi-rbd-node-secret
csi.storage.k8s.io/node-stage-secret-namespace: rook-ceph
reclaimPolicy: Delete
rook-ceph-block class in PVCs.Longhorn is a lightweight, distributed block storage solution ideal for edge and small-to-medium clusters.
helm repo add longhorn https://charts.longhorn.io
helm install longhorn longhorn/longhorn --namespace longhorn-system
longhorn storage class. Use it in PVCs to provision block volumes dynamically.A StorageClass defines how PVs are dynamically created (e.g., using Ceph, Longhorn). Key parameters include:
kubernetes.io/no-provisioner for static, rook-ceph.rbd.csi.ceph.com for Ceph).WaitForFirstConsumer (delays binding until a Pod is scheduled) or Immediate (binds immediately).Delete (removes PV when PVC is deleted) or Retain (preserves PV for reuse).Example of a local storage class (for direct-attached disks):
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Retain
Apply with kubectl apply -f storageclass.yaml.
sudo swapoff -a && sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
echo "overlay br_netfilter" | sudo tee /etc/modules-load.d/containerd.conf
sudo modprobe overlay && sudo modprobe br_netfilter
echo "net.bridge.bridge-nf-call-iptables = 1" | sudo tee /etc/sysctl.d/99-kubernetes.conf
sudo sysctl --system
By following these steps, you can effectively manage Kubernetes storage on Debian, ensuring your stateful applications have reliable, scalable, and performant storage.