Kubernetes Storage & Data Protection›Modules · Cheat sheet & self-check

Modules · wrap-up

Cheat sheet & self-check

Every command from this section on one page.

01 · CSI architecture

CSI objects

kubectl get csidriversInstalled CSI drivers
kubectl get csinodes -o yaml | grep -A3 driversWhich drivers run on which nodes (and volume limits)
kubectl get volumeattachmentsWhich volumes are attached to which nodes
kubectl get sc -o custom-columns=NAME:.metadata.name,PROVISIONER:.provisioner,EXPAND:.allowVolumeExpansion,BINDING:.volumeBindingModeStorageClass summary

Debug

kubectl describe pvc <pvc>Provisioning events
kubectl describe pod <pod> | sed -n '/Events/,$p'Attach/mount events (FailedAttachVolume, FailedMount)
kubectl logs -n <ns> <csi-controller-pod> -c csi-provisionerProvisioner sidecar logs

02 · Longhorn in practice

Install & check

sudo apt install -y open-iscsi nfs-common && sudo systemctl enable --now iscsidNode prerequisites (Debian/Ubuntu)
helm repo add longhorn https://charts.longhorn.ioChart repository
helm install longhorn longhorn/longhorn -n longhorn-system --create-namespaceInstall
kubectl -n longhorn-system get podsManager, driver, UI and engine pods

Inspect

kubectl -n longhorn-system get volumes.longhorn.ioLonghorn volumes, state and robustness
kubectl -n longhorn-system get replicas.longhorn.io -o wideWhere each replica lives
kubectl -n longhorn-system port-forward svc/longhorn-frontend 8080:80Open the Longhorn UI

03 · Rook-Ceph

Rook

kubectl -n rook-ceph get cephclusterCluster phase and health
kubectl -n rook-ceph get pods -l app=rook-ceph-osd -o wideOSD pods and their nodes
kubectl -n rook-ceph exec -it deploy/rook-ceph-tools -- bashOpen the Ceph toolbox

Ceph (inside the toolbox)

ceph statusOverall health, MONs, OSDs, PGs, usage
ceph health detailWhat exactly is wrong
ceph osd treeOSDs by host/rack (the CRUSH hierarchy)
ceph dfCapacity per pool
ceph osd pool ls detailPools, replication size, rules

04 · Snapshots & backups

CSI snapshots

kubectl get volumesnapshotclassSnapshot classes (need the snapshot CRDs + controller)
kubectl get volumesnapshot -n shopSnapshots and readyToUse
dataSource: {name: <snapshot>, kind: VolumeSnapshot, apiGroup: snapshot.storage.k8s.io}In a new PVC: restore from a snapshot

Velero

velero backup create shop-$(date +%F) --include-namespaces shop --snapshot-move-dataBack up a namespace, moving snapshot data to object storage
velero backup create shop-fs --include-namespaces shop --default-volumes-to-fs-backupUse file-system backup for volumes
velero restore create --from-backup <backup> --namespace-mappings shop:shop-restoreRestore into a different namespace (safe test)
velero backup describe <backup> --detailsWhat was included, volume results

05 · Storage performance

fio recipes (run inside a pod on the volume under test)

fio --name=randread --rw=randread --bs=4k --iodepth=32 --size=2G --runtime=60 --time_based --direct=1 --filename=/data/fio.testRandom read IOPS
fio --name=randwrite --rw=randwrite --bs=4k --iodepth=32 --size=2G --runtime=60 --time_based --direct=1 --filename=/data/fio.testRandom write IOPS
fio --name=seqwrite --rw=write --bs=1M --iodepth=8 --size=4G --runtime=60 --time_based --direct=1 --filename=/data/fio.testSequential throughput
fio --name=fsync --rw=write --ioengine=sync --fdatasync=1 --bs=2300 --size=22m --filename=/data/fio.testSmall writes each followed by fdatasync (etcd/DB style)

Observe

iostat -xz 1Per-device utilisation, queue size and await
kubectl top pods --containersCPU of storage agents (replication costs CPU)

06 · Stateful patterns

StatefulSets

kubectl get sts,pods,pvc -l app=dbPods db-0, db-1… and their PVCs data-db-0, data-db-1…
kubectl rollout status sts/dbRolling updates go one pod at a time, highest ordinal first
kubectl scale sts db --replicas=5Scaling adds db-3, db-4 in order

Operators (examples)

kubectl get clusters.postgresql.cnpg.io -ACloudNativePG clusters
kubectl cnpg status <cluster> -n <ns>Primary, replicas, replication lag (cnpg plugin)

07 · Production patterns

Capacity metrics (kubelet)

kubelet_volume_stats_used_bytes / kubelet_volume_stats_capacity_bytesPVC fill ratio
kubelet_volume_stats_inodes_used / kubelet_volume_stats_inodesPVC inode usage
predict_linear(kubelet_volume_stats_available_bytes[6h], 24*3600) < 0Will this PVC fill within 24 h?

Housekeeping

kubectl get pv | grep ReleasedReleased volumes waiting for a decision (Retain)
kubectl get pvc -A | grep -v BoundClaims that aren't bound
kubectl patch pv <pv> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'Protect an important PV from deletion