Score:0

kubernetes local persistent volume for all nodes

ke flag
M.P

I am using the Rancher local provisioner and have a requirement for creating local storage on all the nodes. I use the local-path-storage.yaml to provision the controller, storage class etc.

I create a PVC as below

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-path-pvc
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: 2Gi
  storageClassName: local-path

I see that the below PV is automatically created:

apiVersion: v1
items:
- apiVersion: v1
  kind: PersistentVolume
  metadata:
    annotations:
      pv.kubernetes.io/provisioned-by: rancher.io/local-path
    creationTimestamp: "2022-05-01T19:00:08Z"
    finalizers:
    - kubernetes.io/pv-protection
    name: pvc-8b96804e-06f7-4e5c-a7e5-ace8564fe053
    resourceVersion: "1958451"
    uid: b9cbd171-146b-4963-934b-b5815d522a5f
  spec:
    accessModes:
    - ReadWriteOnce
    capacity:
      storage: 2Gi
    claimRef:
      apiVersion: v1
      kind: PersistentVolumeClaim
      name: local-path-control-pvc
      namespace: my-system
      resourceVersion: "1958366"
      uid: 8b96804e-06f7-4e5c-a7e5-ace8564fe053
    hostPath:
      path: /opt/data/pvc-8b96804e-06f7-4e5c-a7e5-ace8564fe053_my-system_local-path-control-pvc
      type: DirectoryOrCreate
    nodeAffinity:
      required:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - master0
    persistentVolumeReclaimPolicy: Delete
    storageClassName: local-path
    volumeMode: Filesystem
  status:
    phase: Bound

The PVC is associated with 2 different daemon sets. One which deploys a pod on the master and the other that deploys on all worker nodes. The reference would be passed as follows

spec:
  containers:
    volumes:
      -name: test
        persistentVolumeClaim: 
          claimName: local-path-pvc

Question is with the above, the PV is created automatically and nodeAffinity associates only with master. If I remove the PVC reference from Master deployment, then only one of the worker gets a PV and not all workers.

How do I ensure that all nodes get a local PV when pods come up on them?

Thanks, /M

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.