0
votes

Hi i have this problem in kubernetes. I install a deployment with helm that consists of 2 pods i have to put them in two nodes but i want that the persistent volume used by the pods are in the same nodes as the pod are deployed. Is feasible in helm? Thanks

1
Usually Kubernetes handles this itself. (Helm doesn't really come into it; it's just a way of creating the YAML that describes your deployments.) Can you give an example of your current setup and how it doesn't work?David Maze

1 Answers

0
votes

I think you can use Local Persistent Volume See more: local-pv, local-pv-comparision.

Usage of Local Persistent Volumes:

The local volumes must still first be set up and mounted on the local node by an administrator. The administrator needs to mount the local volume into a configurable “discovery directory” that the local volume manager recognizes. Directories on a shared file system are supported, but they must be bind-mounted into the discovery directory.

This local volume manager monitors the discovery directory, looking for any new mount points. The manager creates a PersistentVolume object with the appropriate storageClassName, path, nodeAffinity, and capacity for any new mount point that it detects. These PersistentVolume objects can eventually be claimed by PersistentVolumeClaims, and then mounted in Pods.

After a Pod is done using the volume and deletes the PersistentVolumeClaim for it, the local volume manager cleans up the local mount by deleting all files from it, then deleting the PersistentVolume object. This triggers the discovery cycle: a new PersistentVolume is created for the volume and can be reused by a new PersistentVolumeClaim.

Local volume can be requested in exactly the same way as any other PersistentVolume type: through a PersistentVolumeClaim. Just specify the appropriate StorageClassName for local volumes in the PersistentVolumeClaim object, and the system takes care of the rest!

In your case I will create manually storageclass and use it during chart installation.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: example-local-pv
spec:
  capacity:
    storage: 50Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: example-local-storage
  local:
    path: /mnt/disks/v1
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: example-local-storage
provisioner: kubernetes.io/no-provisioner

and override default PVC storageClassName configuration during helm install like this:

$ helm install --name chart-name --set persistence.storageClass=example-local-storage

Take a look: using-local-pv, pod-local-pv, kubernetes-1.19-lv.