Search code examples
kubernetesazure-aksazure-disk

Attach new azure disk volume per pod in Kubernetes deployment


I have a Kubernetes Deployment app with 3 replicas, which needs a 7GB storage for each replica, I want to be able to attach a new empty azureDisk storage to be mounted into each pod/replica created in this deployment.

Basically I have the following restrictions:

  • I must use Deployment, not a Statefulset
  • Each time a pod dies and a new pod is up, it shouldn't have a state, and it will have a new empty azureDisk attached to it.
  • the pods do not share their storage, each pod has its own 7GB storage.
  • the pods need to use azureDisk because I need a 7GB storage on demand, which means, dynamically creating azureStorage when I scale my deployment replicas.

When using azureDisk, I need to use it with Access mode type ReadWriteOnce (as says in the docs ) and it will attach the only 1 pod to this disk, that's found, but, that only works if I have 1 pod, if I have more than 1 pod, I can't use the same claim... is there any way to dynamically ask for more storages like the one in the first claim?

NOTE 1: I know there is a volumeClaimTemplates, but that's only related to a Statefulset.

NOTE 2: I don't care if a pod restarts 100 times, and this in turn creates 100 PV which only 1 is used, that is fine.


Solution

  • I'm not sure why you need to use a StatefulSet but the only I see to do this is to create your own operator for your application. The operator would have a controller that manages your pods similar to what a ReplicaSet does but with the exception that for every new pod that is instantiated a new PVC is created.

    It might just be better to figure out how to run your application in a StatefulSet and use VolumeClaimTemplates

    ✌️