How do I use a raw volume with a database on Kubernetes?

HOW TO -️ October 18, 2021

I'm trying to figure out how to launch a web application in a Kubernetes cluster on AWS. Right now I'm not certain about a database. I can see that one can use raw block volumes, which are supposedly faster:

This mode is useful to provide a Pod the fastest possible way to access a volume, without any filesystem layer between the Pod and the volume.

And they seem to be recommended particularly for databases:

There are some specialized applications that require direct access to a block device because, for example, the file system layer introduces unneeded overhead. The most common case is databases, which prefer to organize their data directly on the underlying storage.

By databases they supposedly mean PostgreSQL, MariaDB, Redis, whatever.

As such, I wonder if I should use raw block volumes for databases. Because on one hand they recommend it, but I didn't see an example. If so, should I create a custom database image to mount the device into the directory? Interestingly, Kubegres doesn't seem to be using block volumes:

My test yaml file:

ERROR Rendering Code Block


Are you using some Managed Kubernetes Service like EKS? And are you just trying to attach a Disk/SSD as a PVC ? Can you show where is the info where "they recommend it"? @KristianKanchev Indeed, I was probably too succinct. See the updated question. I'm using EKS. That's probably the best option on AWS. And I've managed to attach a EBS volume to the container as you can probably see. Not sure if that can be called a disk/SSD. They question is about make a database use the device. And if it's worth it. Yes, EBS is an SSD as per this document. It's good that you are using EKS, for example, we use MongoDB which uses a PVC from a snapshot, so it is totally worth it depending on what you need. I suggest you use the CSI driver for managing your PVC and EBS CSI driver doc. So for the other question, I suggest you see how to deploy a WordPress app on EKS as it will use the similar setup you are going for with the PVC, then redo it for your app. Example HowTo @KristianKanchev Thanks for the example. I've got to inspect it more closely. But at first glance, it doesn't use raw block volumes :) When I said "worth it," I meant them (raw block volumes). Should I consider that as, "You don't normally need them, particularly with PostgreSQL, MariaDB, ..."? Any advantages of the CSI driver you can name off the top of your head? I would read through this => Link I have not worked that much with raw block volumes, I directly jumped in with CSI driver, so my opinion will not be valid and will lead to CSI.