Close

Persistent Volume strategies for BareMetal

A project log for Project Dandelion

Easy 64bit Ubuntu 20.04 microk8s on Raspberry Pi 4

CarbonCycleCarbonCycle 11/27/2020 at 06:440 Comments

1. Pin the tail on the Donkey.   Manual PVC placement to a specific PV

The storageClass declaration

---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: db-storage
provisioner: kubernetes.io/no-provisioner
reclaimPolicy: Retain
# must use WaitForFirstConsumer to enable topology-aware scheduling, won't bind PVS until a pod using it is scheduled
volumeBindingMode: WaitForFirstConsumer


A brief explanation of the sc is:

provisioner - none. Well, actually its a protein-robot (you) provisioner.

reclaimPolicy - There are others, this one is appropriate for persisting things like databases.
volumeBindingMode - This is key for the method.  The PV will WaitForFirstConsumer.

The Persistent Volume  declaration

---
apiVersion: v1
kind: PersistentVolume
metadata:
   name: PVname
spec:
  capacity:
    storage: 1Gi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  claimRef:
    namespace: ""
    name: ""
  storageClassName: db-storage
  local:
    path: /mnt/pv1
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - <FQDN-dns-hostname>
 

Design:
The idea is to create a valid PV object and have it associated with a specific node where the storage exists. Once deployed, the two items with empty quotes not appear when you edit the pv. claimRef will be "claimRef: {}".  Once you have the PVC name and namespace (found in the waiting pod's describe output), edit the pv object ( kubectl edit pv PVname ) and add those two back with the namespace name and PVCname found waiting ( kubectl get pvc -n namespace-name ).

A brief explanation for the pv:

PVname - I like to use a name that indicates the size of the physical storage.
accessModes - This means only one node can directly write to the storage, not a shared storage in that sense.
persistentVolumeReclaimPolicy - this provides some persistence guarantee.
claimRef - described above.
storageClassName - is chosen to obtain the desired volumeBindingMode.
path - the actual path on the host. Should be in /etc/fstab and mount at boot.
nodeAffinity - this section associates the physical storage to a specific node/host.  Look at a node describe to find the specific string in

kubernetes.io/hostname

Discussions