Attach vs mount vs format — the three CSI operations and their separation
What you'll learn
- Distinguish attach, mount, and format in the CSI lifecycle
- Trace the operations from volume creation to Pod mount
- Explain why format is separated from mount and when format happens
- Identify the failure modes at each stage
Prerequisites
Verified against Kubernetes 1.34.x · kubeadm 1.34.x · kubectl 1.34.x · etcd 3.6.x · CoreDNS 1.11.x · containerd 1.7.x / 2.x · 2026-08-16
Three operations take a volume from “exists on the backend” to “filesystem mounted in a Pod”: attach, mount, and format. Each has a specific responsibility; each happens at a specific layer; each can fail independently. This lesson walks the three and the production discipline for diagnosing failures at each stage.
The three operations
sequenceDiagram
participant CP as CSI controller plugin
participant BE as Backend
participant NP as CSI node plugin
participant N as Node (kernel)
participant P as Pod
Note over CP,BE: Attach (controller-level)
CP->>BE: attach volume to node
BE-->>CP: device path (/dev/xvdba)
Note over NP,N: Format (node-level, first time only)
NP->>N: mkfs.ext4 /dev/xvdba
Note over NP,N: Mount (node-level)
NP->>N: mount /dev/xvdba /var/lib/kubelet/plugins/.../mount
Note over NP,N: Publish (node-level)
NP->>N: bind-mount stagingPath -> podPath
Note over P,N: Pod sees the filesystem
P->>N: read/write at /var/lib/app
Attach: the controller-level operation
Attach is ControllerPublishVolume (and its inverse,
ControllerUnpublishVolume). It is called by the
kube-controller-manager, executed by the CSI controller
plugin, and makes the volume visible to a node at the
hardware level.
message ControllerPublishVolumeRequest {
string volume_handle = 1;
string node_id = 2;
VolumeCapability volume_capability = 3;
bool readonly = 4;
map<string, string> secrets = 5;
string volume_context = 6;
}
What attach does:
- EBS:
ec2:AttachVolumeAPI call; the EBS volume is attached to the EC2 instance as/dev/xvdba(or similar). - GCE PD:
disks.attachAPI call; the PD is attached to the GCE instance. - Ceph RBD:
rbd mapcommand; the RBD image is mapped to a block device on the node.
The result is a device path on the node, accessible via the kernel’s block layer. The device is not yet mounted or formatted.
Format: the node-level operation
Format is part of NodeStageVolume. It happens on the
node, executed by the CSI node plugin, and prepares the
filesystem on the block device.
What format does:
- Check if the device has a filesystem (e.g., via
blkid). - If not, create a filesystem (e.g.,
mkfs.ext4,mkfs.xfs). - The fsType is determined by the
VolumeCapability’sFilesystemVolume.fs_type.
Format happens once per volume (the first time the volume is staged on any node). Subsequent NodeStageVolume calls are idempotent: the format is skipped if the filesystem already exists.
# Manual format (for understanding)
mkfs.ext4 /dev/xvdba
# Filesystem UUID: ...
Mount: the node-level operation
Mount is the second part of NodeStageVolume (after
format). It happens on the node, executed by the CSI node
plugin, and makes the filesystem accessible at the
staging path.
What mount does:
- Mount the block device to the staging path (e.g.,
/var/lib/kubelet/plugins/<csi-driver>/pvc-<pvc-uid>/mount). - Use the mount options from
VolumeCapability.FilesystemVolume.mount_flags. - Verify the mount succeeded.
After mount, the staging path contains the filesystem’s contents. The Pod’s bind-mount (from NodePublishVolume) makes the contents visible inside the container.
# Manual mount (for understanding)
mount -t ext4 -o noatime /dev/xvdba /var/lib/kubelet/plugins/.../mount
The ordering matters
The operations must happen in order:
- Create (controller): the volume exists on the backend.
- Attach (controller): the volume is attached to the node.
- Stage (node, includes format + mount): the volume is formatted and mounted to the staging path.
- Publish (node): the volume is bind-mounted to the Pod’s target path.
Each operation’s failure blocks the next:
- Create fails: no volume to attach.
- Attach fails: no device to format/mount.
- Stage fails: no filesystem to bind-mount.
- Publish fails: Pod cannot access the filesystem.
Failure modes at each stage
| Stage | Failure mode | Diagnostic |
|---|---|---|
| Create | Backend API error, quota exceeded | Controller plugin logs |
| Attach | Instance type mismatch, AZ mismatch | Controller plugin logs + cloud metrics |
| Format | Device has unexpected filesystem, mkfs fails | Node plugin logs + dmesg |
| Mount | Filesystem error, mount options invalid | Node plugin logs + dmesg |
| Publish | Staging path missing, permission denied | Node plugin logs + kubelet logs |
The diagnostic ladder is: PV/PVC events -> controller plugin logs -> node plugin logs -> node kernel logs (dmesg) -> cloud-provider metrics.
Volume mode Block vs Filesystem
The volumeMode in the PVC affects which operations
happen:
- Filesystem (default): format + mount + bind-mount. The Pod sees a directory.
- Block: attach only, no format, no mount, no bind-mount. The Pod sees a raw block device.
For Block volumes:
- No
mkfsis run; the device is exposed raw. - The Pod’s
volumeDevices(notvolumeMounts) reference the volume. - The application manages the filesystem (e.g., a database using a custom block-based storage engine).
Quiz
Knowledge check · 4 questions
Q1. Which operation is responsible for creating the filesystem on the block device?
Q2. Format is a one-time operation per volume; subsequent stages skip the format if a filesystem already exists.
Q3. A Pod is stuck in ContainerCreating. The events show `FailedMount` at the stage phase. Walk through the attach-mount-format diagnostic.
Pod stuck for 10 minutes. PVC Bound. The CSI controller plugin successfully created and attached the volume. The CSI node plugin reports `mkfs.ext4: /dev/xvdba contains a filesystem` but then fails.
Q4. Explain the difference between attach, mount, and format and why they are separate operations.
Passing score: 75%. Answers are checked in this browser.
Production discipline
- Each operation has its own failure mode. The diagnostic ladder is attach -> format -> mount -> publish.
- Format is idempotent. It checks for an existing filesystem before formatting.
- Block mode bypasses format and mount. The Pod sees a raw device.
- Mount options are part of the StorageClass. Specify them in the StorageClass for the workload.
- Test format behavior on existing volumes. A CSI driver that always formats will overwrite data.