Raw Block Volumes
What You'll Learn
You'll learn how to provision and consume raw block devices in Kubernetes instead of traditional filesystems, giving applications direct access to storage blocks.
Understanding Raw Block Volumes
Until now, you've worked with volumes that present a filesystem to your pods—think of directories and files you can navigate. But some applications (like databases or storage systems) prefer working with raw block storage: direct access to storage blocks without the overhead of a filesystem layer.
Imagine the difference between receiving a pre-organized filing cabinet (filesystem) versus getting raw, blank filing drawers you can organize exactly how you want (block device). The second option gives specialized applications more control and often better performance.
Provisioning Raw Block Volumes
To request a raw block volume instead of a filesystem, you set volumeMode: Block in your PersistentVolumeClaim:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: raw-block-pvc
spec:
accessModes:
- ReadWriteOnce
volumeMode: Block # Request raw block device
resources:
requests:
storage: 10Gi
storageClassName: fast-ssd
Consuming in Pods
Instead of volumeMounts, you use volumeDevices to attach the block device:
apiVersion: v1
kind: Pod
metadata:
name: block-consumer
spec:
containers:
- name: app
image: myapp
volumeDevices: # Not volumeMounts!
- name: data
devicePath: /dev/xvda # Appears as a block device
volumes:
- name: data
persistentVolumeClaim:
claimName: raw-block-pvc
The application now sees /dev/xvda as a raw block device it can read/write directly.
Key Takeaway: Raw block volumes using volumeMode: Block provide direct block device access to applications that need low-level storage control, bypassing filesystem overhead for better performance in specialized workloads.