Question: How can I use raw devices attached to the host within the pod as block device.
I tried using "hostPath" with type "BlockDevice"
volumes:
- my-data:
hostPath:
path: /dev/nvme1n2
type: BlockDevice
containers:
.....
volumeDevices:
- name: my-data
devicePath: /dev/sda
This configuration gives me the below error.
Invalid value: "my-data": can only use volume source type of PersistentVolumeClaim for block mode
Can I achieve this using PersistentVolume
and PersistentVolumeClaim
? Can someone help me with an example config. Appreciate the help.
Support for Block devices in K8s allows user and admins to use PVs & PVCs for raw block devices to be mounted in Pods. Excerpts below show a small use-case.
/dev/xvdf
.kind: PersistentVolume
apiVersion: v1
metadata:
name: local-raw-pv
spec:
volumeMode: Block
capacity:
storage: 100Gi
local:
path: /dev/xvdf
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: block-pvc
spec:
accessModes:
- ReadWriteOnce
volumeMode: Block
resources:
requests:
storage: 10Gi
/dev/xvdf
inside pod at path /dev/xvda
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