Home > OS >  How to use Shared Drive as multiple Kubernetes PV in Homelab
How to use Shared Drive as multiple Kubernetes PV in Homelab

Time:10-21

I have homelab. Window Host and Vmware workstation

1 Master Node
3 Worker Nodes

All nodes have the windows drive mounted and available /external

I want to run multiple tools like jenkins, nexus, nessus, etc and want to use persistent volumes in external drive so that even if i create new EKS clusters then volumes stay there for ever and i can reuse them

So i want to know whats the best to use it

  1. Can i create single hostPath PV and then each pod can claim exmaple 20GB from it
  2. Or I have to create PV for each pod with hostPath and then claim it in POD

So is there 1:1 relationship with PV and PVC ? or one PV can have multiple claims in diff folders?

  1. Also if recreate CLuster and create PV from same hostPath , will my data be there ?

CodePudding user response:

You can use local volume instead of hostPath to experiment with SC/PVC/PC. First, you create the StorageClass:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: shared
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

Then you provision the PersistentVolume available on each node, here's an example for one node:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: shared-pv-1
spec:
  capacity:
    storage: 20Gi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: shared
  local:
    path: <path to the shared folder>
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - <your node name>

And the claim that allows you to mount the provisioned volume in a pod:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: shared-pv-1
spec:
  storageClassName: shared
  volumeMode: Filesystem
  resources:
    requests:
      storage: 20Gi
  accessModes:
  - ReadWriteOnce

Here's an example pod that mounts the volume and write to it:

apiVersion: v1
kind: Pod
metadata:
  name: busybox-1
spec:
  restartPolicy: Never
  volumes:
  - name: shared
    persistentVolumeClaim:
      claimName: shared-pv-1
  containers:
  - name: busybox-1
    image: busybox
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - name: shared
      mountPath: /data
    command: ["ash","-c","while :; do echo \"$(date)\tmessage from busybox-1.\"  >> /data/message.txt; sleep 1; done"]

For local volume, by default the data written will require manual cleanup and deletion. A positive side effect for you as you would like the content to persist. If you like go further to experiment CSI alike local volume, you can use this Local Persistence Volume Static Provisioner.

  • Related