Skip to main content
RunBook Academy

CephLXXXVII · Kubernetes CephFSKubernetes CephFS

Shared CephFS volumes across pods

Advanced⏱ ~18 minkubectlceph

What you'll learn

  • Explain the guarantees CephFS provides to concurrent writers
  • Use the locking mechanisms that work
  • Recognise patterns that fail despite POSIX semantics
  • Design applications for shared volumes

Prerequisites

None — start here.

Verified against Ceph Tentacle 20.2.x · Ceph Squid 19.2.x (supported previous) · cephadm matches the verified Ceph release · podman 4.x · csi-rbd and csi-cephfs current · RBD / CephFS / RGW current (matches Ceph release) · Linux kernel 5.15+ (5.10 minimum) · Ubuntu 24.04 LTS (Ceph host baseline) · Debian 12 (Bookworm) (Ceph host baseline) · Rocky Linux / RHEL / AlmaLinux 9.x (Ceph host baseline) · Proxmox VE 9.x (cross-course integration) · Kubernetes 1.31+ (cross-course integration) · 2026-08-18

Not yet marked complete on this device.

Why this matters in production

CephFS gives several pods a genuinely shared POSIX filesystem, which is more than most shared storage provides and less than some applications assume.

What is guaranteed

GuaranteeProvided
A write visible to other clients after it completesyes
POSIX read/write semanticsyes
fcntl advisory locks across clientsyes
flock across clientsyes
Atomic rename within the filesystemyes
Directory operations serialised correctlyyes
O_APPEND atomicity across clientsyes
Byte-range lockingyes, advisory
Mandatory lockingno
spec:
  accessModes: [ReadWriteMany]
  storageClassName: ceph-fs

The locking that works

import fcntl
with open('/data/shared.lock', 'w') as f:
    fcntl.flock(f, fcntl.LOCK_EX)
    # exclusive across every pod on every node
    fcntl.flock(f, fcntl.LOCK_UN)
# from a shell
flock /data/shared.lock -c 'do-the-thing'

Both flock and fcntl locks are coordinated by the MDS and work across nodes, which is the property that makes CephFS suitable for leader election and coordinated access.

Patterns that fail despite POSIX semantics

PatternProblem
Assuming a lock survives a client evictionthe MDS releases it
Relying on lock ordering for correctnessno ordering guarantee between waiters
Using file existence as a locknot atomic; use O_EXCL
Heavy small-file metadata operationsMDS becomes the bottleneck
Many pods appending to one filecorrect but heavily contended
Assuming close-to-open consistency is enoughCephFS is stronger, but applications may assume weaker
# atomic creation, correct
fd = os.open('/data/lock', os.O_CREAT | os.O_EXCL | os.O_WRONLY)

The eviction case

ceph tell mds.0 client ls
ceph osd blocklist ls
A client that loses contact with the MDS is eventually evicted
  → its capabilities are revoked
  → its locks are released
  → another pod can acquire them
  → the evicted pod may still believe it holds the lock

Applications relying on locks for correctness must handle losing them, which means checking a fencing token or re-validating rather than assuming continuity.

Designing for shared volumes

RequirementApproach
Coordinated writesflock with re-validation after any I/O error
Independent per-pod dataseparate directories, no coordination needed
High metadata rateconsider whether the workload suits a filesystem
Leader electiona dedicated mechanism, not a file lock
Append-only log from many writersone writer, others queue

Quiz

Knowledge check · 4 questions

  1. Q1. What makes ReadWriteMany meaningful for CephFS and impossible for RBD?

  2. Q2. A CephFS `flock` held by a pod persists even if that pod's client is evicted by the MDS.

  3. Q3. Design an application for a shared CephFS volume.

    An application will run several replicas writing to a shared CephFS volume, using a lock file to coordinate exclusive sections.

  4. Q4. Why is using file existence as a lock incorrect on CephFS?

Passing score: 75%. Answers are checked in this browser.

Production discipline

Use flock or fcntl for coordination on shared CephFS volumes — both are arbitrated by the MDS and work across nodes — and treat any I/O error as a signal the client may have been evicted and its locks released. Never use file existence as a lock; O_CREAT | O_EXCL is the atomic primitive.

Cross-course references

  • Kubernetes: leases and leader election exist because file locks are not sufficient
  • Linux: NFS and cluster filesystems face identical lock-recovery semantics