Reuse existing Hetzner Cloud Volume - csi-driver

Is it possible to reuse an existing Hetzner Cloud Volume?

Every new PVC creates a random/unique name/identifier, which is not based on the volume or PVC name, so in some cases I end up with duplicate volumes on Hetzner's side, which I then have to clean up manually.

This made me wonder if there's a name, identifier or annotation that I could utilize to ensure that the Persistent Volume name is set to a specific name every time, and whether the CSI driver would pick up on that, connecting the Hetzner Cloud Volume with the Kubernetes volume/volume claim?

Asked Oct 02 '21 13:10
avatar Dids
Dids

5 Answer:

Just copy Volume ID and use it as volumeHandle - specify PV with

csi:
    volumeHandle: "xxxxx"
    driver: csi.hetzner.cloud
    fsType: ext4

in you spec:

1
Answered Sep 10 '20 at 22:46
avatar  of nazarkulyk
nazarkulyk

Thanks! While that sounds like it would indeed do what I want, it unfortunately sounds like wouldn't fit well into the infrastructure automation, eg. when the volume is first created/provisioned I would have to manually keep track of the volume handle/ID.

Unless the CSI driver syncs all Hetzner Cloud Volumes to Kubernetes as PVs, meaning I could automate the HCloud Volume part of it before creating the Kubernetes cluster, then using the name/ID of that?

1
Answered Sep 11 '20 at 05:59
avatar  of Dids
Dids

Never mind, this did indeed work exactly as described! I simply created the Hetzner Cloud Volume in Terraform first, then passed the ID to the PV's volumeHandle, which worked perfectly.

1
Answered Sep 11 '20 at 08:02
avatar  of Dids
Dids

I am sorry. Do you have a complete example for a pv definition with a given volumeHandle? I am new to kubernetes and I don't get it done.

  • Do I have to create the volume in the hetzner cloud before I create the PC/PVC? And if so, do I have to attach thee volume to a hetzner server?
  • And how exactly does a pv and pvc resourcee looks like with the snippet you pasted above?

I am thankful for any help, Tobias

1
Answered Apr 28 '21 at 18:55
avatar  of tobias-neubert
tobias-neubert

Ok, I found my mistake. The volumeHandle must be its ID and not its name. It is bound now to my pod.

1
Answered Apr 28 '21 at 18:58
avatar  of tobias-neubert
tobias-neubert