Body: <p>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:</p>
  <blockquote>
  <p>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.</p>
  </blockquote>
  <p><a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/persistent-volumes/</a></p>
  <p>And they seem to be recommended particularly for databases:</p>
  <blockquote>
  <p>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.</p>
  </blockquote>
  <p><a href="https://kubernetes.io/blog/2019/03/07/raw-block-volume-support-to-beta/" rel="nofollow noreferrer">https://kubernetes.io/blog/2019/03/07/raw-block-volume-support-to-beta/</a></p>
  <p>By databases they supposedly mean PostgreSQL, MariaDB, Redis, whatever.</p>
  <p>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:</p>
  <p><a href="https://github.com/reactive-tech/kubegres/blob/v1.12/controllers/spec/template/yaml/PrimaryStatefulSetTemplate.yaml#L19-L27" rel="nofollow noreferrer">https://github.com/reactive-tech/kubegres/blob/v1.12/controllers/spec/template/yaml/PrimaryStatefulSetTemplate.yaml#L19-L27</a></p>
  <p>My test yaml file:</p>
  <pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: mydeployment
    namespace: myns
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: myapp
    template:
      metadata:
        labels:
          app: myapp
      spec:
        containers:
        - name: app
          image: mariadb
          env:
          - name: MARIADB_ALLOW_EMPTY_ROOT_PASSWORD
            value: '1'
          volumeDevices:
          - name: persistent-storage
            devicePath: /dev/xvda
        volumes:
        - name: persistent-storage
          persistentVolumeClaim:
            claimName: ebs-claim
  ---
  apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: ebs-claim
    namespace: myns
  spec:
    accessModes:
    - ReadWriteOnce
    storageClassName: gp2
    volumeMode: Block
    resources:
      requests:
        storage: 1Gi
  </code></pre>
  
Comments: CC BY-SA 4.0
Comments: 2021-10-16T13:59:51.243Z
Comments: 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"?
Comments: Kristian Kanchev
Comments: CC BY-SA 4.0
Comments: 2021-10-17T07:19:39.470Z
Comments: @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.
Comments: x-yuri
Comments: CC BY-SA 4.0
Comments: 2021-10-17T11:57:29.120Z
Comments: Yes, EBS is an SSD as per [this](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volumes.html) 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](https://docs.aws.amazon.com/eks/latest/userguide/ebs-csi.html).
Comments: Kristian Kanchev
Comments: CC BY-SA 4.0
Comments: 2021-10-17T12:05:12.360Z
Comments: 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](https://avikkundu.medium.com/deploying-wordpress-with-mysql-on-top-of-amazon-eks-27bb99fb088b)
Comments: Kristian Kanchev
Comments: CC BY-SA 4.0
Comments: 2021-10-19T16:08:58.290Z
Comments: @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?
Comments: x-yuri
Comments: CC BY-SA 4.0
Comments: 2021-10-19T16:28:15.900Z
Comments: I would read through this => [Link](https://kubernetes-csi.github.io/docs/raw-block.html) 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.
Comments: Kristian Kanchev
Tags: <kubernetes><databases><kubernetes-volume><persistent-volumes>
Title: How do I use a raw volume with a database on Kubernetes?
UserDisplayName: x-yuri
ThreadText: # How do I use a raw volume with a database on Kubernetes?
  
  (Asked by: username_0 on 2021-10-16)
  
  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.
  
  <https://kubernetes.io/docs/concepts/storage/persistent-volumes/>
  
  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.
  
  <https://kubernetes.io/blog/2019/03/07/raw-block-volume-support-to-beta/>
  
  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:
  
  <https://github.com/reactive-tech/kubegres/blob/v1.12/controllers/spec/template/yaml/PrimaryStatefulSetTemplate.yaml#L19-L27>
  
  My test yaml file:
  
  ```yaml
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: mydeployment
    namespace: myns
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: myapp
    template:
      metadata:
        labels:
          app: myapp
      spec:
        containers:
        - name: app
          image: mariadb
          env:
          - name: MARIADB_ALLOW_EMPTY_ROOT_PASSWORD
            value: '1'
          volumeDevices:
          - name: persistent-storage
            devicePath: /dev/xvda
        volumes:
        - name: persistent-storage
          persistentVolumeClaim:
            claimName: ebs-claim
  ---
  apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: ebs-claim
    namespace: myns
  spec:
    accessModes:
    - ReadWriteOnce
    storageClassName: gp2
    volumeMode: Block
    resources:
      requests:
        storage: 1Gi
  
  ```
  
  **Tags:** kubernetes, databases, kubernetes-volume, persistent-volumes
  
  > **Comments:**
  > **username_1**: 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"?  
  > **username_0**: @username_1 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.  
  > **username_1**: Yes, EBS is an SSD as per [this](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volumes.html) 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](https://docs.aws.amazon.com/eks/latest/userguide/ebs-csi.html).  
  > **username_1**: 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](https://avikkundu.medium.com/deploying-wordpress-with-mysql-on-top-of-amazon-eks-27bb99fb088b)  
  > **username_0**: @username_1 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?  
  > **username_1**: I would read through this => [Link](https://kubernetes-csi.github.io/docs/raw-block.html) 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.  
  
  ---
  
  ## 0 answers
  
  