0

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

M.P
  • 1

0 Answers0