Setup Folder When Setting up Kubernetes Storage



  • I am trying to setup automation around my Kubernetes storage and hitting some problems. I thought I would ask if there is a solution for this in the community.

    The two Kubernetes storage options I am seeing each have a limitation:

    Dynamic Storage: You can't control the name of the Persistent Volume nor the directory that it creates on disk (making it hard to connect to again if needed).

    Static Storage: You have to manually make the folder structure that the Persistent Volume expects.

    Both of these can be overcome with more work. But I find it hard to believe that I am the first person with this issue, so I thought I would ask:

    Is there a way using dynamic storage (aka Storage Classes) to choose the Persistent Volume name and folder structure that is created (so it can be re-connected to)?

    OR

    Is there a way to have a manually created Persistent Volume create the needed folder structure given in the yaml? (This is perferred.)



  • You can't control the name of the Persistent Volume nor the directory that it creates on disk (making it hard to connect to again if needed).

    I'm not entirely sure what you mean here. When you use a https://kubernetes.io/docs/concepts/storage/persistent-volumes/ to request a volume from Kubernetes, you specify the name of the claim. You don't directly specify the name of the PersistentVolume that will be created by the PersistentVolumeClaim, but that's okay: you mount the volume via the claim.

    That is, if I have:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: pgsql-data
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 80Gi
    

    Then I can mount this in a pod like this:

    apiVersion: v1
    kind: Pod
    metadata:
      name: example-pod
    spec:
      containers:
      - name: postgres
        image: docker.io/postgres:14
      volumes:
        - name: psql-data
          persistentVolumeClaim:
            claimName: psql-data
    

    Kubernetes doesn't care about the folder structure on the volume; once the volume is mounted, your application can create whatever folder structure it wants.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2