Skip to main content
Version: 3.1

Raw Block Devices

Summary and Key concepts

Summary:

This article explains how to use Portworx CSI Driver for creating and managing raw block devices in Kubernetes or OpenShift environments. It highlights support for both file and block volume types and describes how to create a PersistentVolumeClaim (PVC) with block volume mode for applications that require raw block devices. The article walks through creating a PersistentVolumeClaim and deployment YAML configurations for using raw block storage with a Kubernetes deployment. Specific instructions for applying these configurations differ slightly based on the environment, whether using kubectl or oc for OpenShift.

Kubernetes Concepts:

  • PersistentVolumeClaim (PVC): A request for storage by a user.
  • VolumeMode: By setting a Block mode in PVCs allows raw block devices to be requested instead of file-based volumes.
  • StorageClass: Defines the class of storage to be used for PVCs.
  • Deployment: A Kubernetes object that manages a replicated application, updating and scaling based on specifications.
  • VolumeDevices: Used to mount raw block devices inside containers.

Portworx Concepts:

The Portworx CSI Driver supports both File and Block volume types in Kubernetes PVCs. While file has more supported features, block support for ReadWriteOnly PVCs was added in Portworx Enterprise in version 2.8.0.

Use cases for Raw Block Devices

If your application has a requirement to consume a raw block device as opposed to a mounted filesystem, this is a perfect use case for Portworx CSI Raw Block devices.

note

Currently, only ReadWriteOnce PVCs can be created with the block volume mode.

Create and use raw block PVCs

In this example we are using the px-csi-db storage class out of the box. Please refer CSI Enabled Storage Classes for list of available CSI enabled storage classes offered by Portworx.

  1. Create a PVC spec that references the portworx-csi-sc as seen below in a YAML file named raw-block-pvc.yaml:

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
    name: px-csi-raw-block-pvc
    spec:
    volumeMode: Block
    storageClassName: px-csi-db
    accessModes:
    - ReadWriteOnce
    resources:
    requests:
    storage: 2Gi
  2. Apply the raw-block-pvc.yaml spec to create the raw block PVC:

    kubectl apply -f raw-block-pvc.yaml

  3. Create a deployment SPEC that references the above raw block PVC in raw-block-deployment.yaml:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: ioping
    spec:
    selector:
    matchLabels:
    app: ioping
    strategy:
    rollingUpdate:
    maxSurge: 1
    maxUnavailable: 1
    type: RollingUpdate
    replicas: 1
    template:
    metadata:
    labels:
    app: ioping
    version: "1"
    spec:
    containers:
    - name: ioping
    image: hpestorage/ioping
    command: [ "ioping" ]
    args: [ "/dev/xvda" ]
    volumeDevices:
    - name: raw-device
    devicePath: /dev/xvda
    volumes:
    - name: raw-device
    persistentVolumeClaim:
    claimName: px-csi-raw-block-pvc
  4. Apply the raw-block-deployment.yaml spec to create the deployment utilizing our raw block PVC:

    kubectl apply -f raw-block-deployment.yaml