<p>Question: How can I use raw devices attached to the host within the pod as block device.</p>

<p>I tried using "hostPath" with type "BlockDevice"</p>

<pre><code>volumes:
- my-data:
  hostPath:
    path: /dev/nvme1n2
    type: BlockDevice
</code></pre>

<pre><code>containers:
.....
  volumeDevices:
  - name: my-data
    devicePath: /dev/sda
</code></pre>

<p>This configuration gives me the below error.</p>

<pre><code>Invalid value: "my-data": can only use volume source type of PersistentVolumeClaim for block mode
</code></pre>

<p>Can I achieve this using <code>PersistentVolume</code> and <code>PersistentVolumeClaim</code> ? Can someone help me with an example config. Appreciate the help.</p>

Colin
<p><a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#raw-block-volume-support" rel="noreferrer">Support for Block devices in K8s</a> allows user and admins to use PVs &amp; PVCs for raw block devices to be mounted in Pods. Excerpts below show a small use-case.</p>

<ul>
<li>Create a PV which refers the Raw device on host say <code>/dev/xvdf</code>.</li>
</ul>

<pre><code>kind: PersistentVolume
apiVersion: v1
metadata:
  name: local-raw-pv
spec:
  volumeMode: Block
  capacity:
    storage: 100Gi
  local:
    path: /dev/xvdf
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
</code></pre>

<ul>
<li>Create a PVC claiming the block device for applications</li>
</ul>

<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: block-pvc
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Block
  resources:
    requests:
      storage: 10Gi
</code></pre>

<ul>
<li>Create pod with the above claim which will mount the host device <code>/dev/xvdf</code> inside pod at path <code>/dev/xvda</code></li>
</ul>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: pod-with-block-volume
spec:
  containers:
    - name: some-container
      image: ubuntu
      command: ["/bin/sh", "-c"]
      args: [ "tail -f /dev/null" ]
      volumeDevices:
        - name: data
          devicePath: /dev/xvda
  volumes:
    - name: data
      persistentVolumeClaim:
        claimName: block-pvc
</code></pre>
