skip to Main Content

I have attached an EBS volume to one of the nodes in my cluster and I want that whatever pod are coming up, irrespective of the nodes they are scheduled onto, should use that EBS volume. is this possible?

My approach was to create a PV/PVC that mounts to that volume and then use that PVC in my pod, but I am not sure if it’s mounting to same host that pod comes up in or a different host.

YAML for Storage Class

kind: StorageClass
metadata:
  name: local-path
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: Immediate
allowVolumeExpansion: true
reclaimPolicy: Delete

PV.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: redis-pv
  labels:
    type: local
spec:
  capacity:
    storage: 200Mi
  storageClassName: local-path
  claimRef:
    namespace: redis
    name: data-redis-0
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/mnt2/data/redis"

PVC.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-redis-0
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 200Mi
  storageClassName: local-path

no when i am trying to schedule a pod the storage is also getting mounted on the same node instead

2

Answers


  1. you are using local path you can not do it.

    There is a different type of AccessMount ReadWriteMany, ReadWriteOnce, and ReadyWriteOnly with PVC.

    A PersistentVolumeClaim (PVC) is a request for storage by a user. It
    is similar to a Pod. Pods consume node resources and PVCs consume PV
    resources. Pods can request specific levels of resources (CPU and
    Memory). Claims can request specific size and access modes (e.g., they
    can be mounted ReadWriteOnce, ReadOnlyMany or ReadWriteMany, see
    AccessModes).

    Read More at : https://kubernetes.io/docs/concepts/storage/persistent-volumes/

    Yes you can mount the multiple PODs to a single PVC but in that case, you have to use the ReadWriteMany. Most people use the NFS or EFS for this type of use case.

    EBS is ReadWriteOnce, so it won’t be possible to use the EBS in your case. you have to either use NFS or EFS.

    you can use GlusterFs in the back it will be provisioning EBS volume. GlusterFS support ReadWriteMany and it will be faster compared to EFS as it’s block storage (SSD).

    For ReadWiteMany you can also checkout : https://min.io/

    Find access mode details here : https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes

    Login or Signup to reply.
  2. I have attached an EBS volume to one of the nodes in my cluster and I want that whatever pod are coming up, irrespective of the nodes they are scheduled onto, should use that EBS volume. is this possible?

    No. An EBS volume can only be attached to at most one EC2 instance, and correspondingly, one Kubernetes node. In Kubernetes terminology, it only allows the ReadWriteOnce access mode.

    It looks like the volume you’re trying to create is the backing store for a Redis instance. If the volume will only be attached to one pod at a time, then this isn’t a problem on its own, but you need to let Kubernetes manage the volume for you. Then the cluster will know to detach the EBS volume from the node it’s currently on and reattach it to the node with the new pod. Setting this up is a cluster-administration problem and not something you as a programmer can do, but it should be set up for you in environments like Amazon’s EKS managed Kubernetes.

    In this environment:

    • Don’t create a StorageClass; this is cluster-level configuration.
    • Don’t manually create a PersistentVolume; the cluster will create it for you.
    • You should be able to use the default storageClass: in your PersistentVolumeClaim.
    • You probably should use a StatefulSet to create the PersistentVolumeClaim for you.

    So for example:

    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: redis
    spec:
      volumeClaimTemplates: # automatically creates PersistentVolumeClaims
        - metadata:
            name: data-redis
          spec:
            accessModes: [ReadWriteOnce] # data won't be shared between pods
            resources:
              requests:
                storage: 200Mi
            # default storageClassName:
      template:
        spec:
          containers:
            - name: redis
              volumeMounts:
                - name: data-redis
                  mountPath: /data
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search