0

I am new to k8s, but have been exploring persistent volumes, and the ability to actually limit capacity is only in alpha stage, and needs to be manually enabled to work per: https://kubernetes.io/docs/concepts/storage/storage-capacity/#enabling-storage-capacity-tracking

I'd much rather build a disk image file, such as:

fallocate -l 50M mytest.img
mke2fs -t ext4 mytest.img

And then mount it as a volume in a pod in k8s, but I am not sure how. I've tried using hostPath, but it failed when trying as a File and a Directory type. Considering the plethora of volume mounting types, hopefully I just am missing the proper command.

I know I can mount the image somewhere on the host and then point hostPath to the mount, but host mounting shouldn't be required.

Edit: If this isn't possible, can someone suggest an alternative image file type that I can create a limited (but expandable) file that is mountable in k8s?

5
  • I would guess the cheapest way is via the deprecated flex volume source (and the gory details), but surely one of the existing CSI drivers meets your needs?
    – mdaniel
    Dec 18, 2020 at 20:21
  • flex volume, besides being deprecated, is definitely ugly - I'm still looking to see what drivers may meet my needs. Hopefully someone has done this and can point me to the correct driver/setting for this Dec 18, 2020 at 20:30
  • Would raw block volumes work for you? kubernetes.io/docs/concepts/storage/persistent-volumes/… Dec 18, 2020 at 23:20
  • Block volumes look more cumbersome than volume files - I'd also have to consider how to locate/back up/push files to the block volume in case of a cluster failure. An image file is simple to back up (part of the host filesystem), and can trivially be mounted to get/set data using built in linux tools. Dec 19, 2020 at 0:07
  • I've moved on to Longhorn for volume management, and am able to mount the volumes easily on the host with that. Leaving this issue open in case someone can find an answer to the original question. Dec 29, 2020 at 20:19

1 Answer 1

0

This is a community wiki answer summing up the current status of this question and the workaround. Posted for better visibility. Feel free to edit and expand it.

Officially Enabling storage capacity tracking is still in it's aplha:

Storage capacity tracking is an alpha feature and only enabled when the CSIStorageCapacity feature gate and the storage.k8s.io/v1alpha1 API group are enabled. For details on that, see the --feature-gates and --runtime-config kube-apiserver parameters.

And flexVolume is deprecated.

The current workaround is to use the Longhorn:

Longhorn is a distributed block storage system for Kubernetes. Longhorn is cloud native storage because it is built using Kubernetes and container primatives.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .