Spark Kubernetes shuffle storage
| Also known as | Spark local storage on Kubernetes, spark-local-dir volumes |
|---|---|
| Field | Distributed data processing |
| Key parts | emptyDir scratch volumes, spark-local-dir-* volumes, on-demand persistent volume claims, KubernetesLocalDiskShuffleDataIO
|
| Open source implementations | Apache Spark |
| Related | Shuffle, Executor, Spark on Kubernetes, Executor decommissioning, Spark Kubernetes pod template |
In Apache Spark, shuffle storage on Kubernetes is the set of pod volumes where executors write shuffle files and spill data; by default these are Kubernetes emptyDir volumes that last only as long as the executor pod.[1] Spark on Kubernetes has no external shuffle service, so shuffle files written by an executor are normally lost when its pod goes away.[2] Spark offers RAM-backed volumes, host disks, persistent volume claims (PVCs) that the driver reuses, and a shuffle plugin that recovers files from reused PVCs.[1]
Where does Spark write shuffle and spill data on Kubernetes by default?
When no volume is configured as local storage, Spark on Kubernetes mounts one emptyDir volume for each directory in spark.local.dir or the SPARK_LOCAL_DIRS environment variable. If neither is set, Spark creates and configures a default directory.[1]
An emptyDir volume uses the ephemeral storage of the node and does not outlive the pod. Shuffle files on it disappear when the executor pod is deleted.[1]
How does spark.kubernetes.local.dirs.tmpfs work?
spark.kubernetes.local.dirs.tmpfs (default false, added in Spark 3.0.0) sets the medium of the scratch emptyDir volumes to Memory, so they are tmpfs, RAM-backed volumes.[3][4] The documentation suggests it for nodes without local disks, where many executors writing to network-mounted storage can be slow.[1]
With tmpfs, data in the local directories counts against the pod's memory. The Spark documentation suggests raising spark.{driver,executor}.memoryOverheadFactor to leave room for it.[1]
How do spark-local-dir volumes work?
Any volume mounted through the Spark volume properties whose name starts with spark-local-dir- is used as local storage for shuffle and spill instead of the default emptyDir.[1] Volume properties have the form spark.kubernetes.executor.volumes.[VolumeType].[VolumeName].mount.path, and the supported types are hostPath, emptyDir, nfs and persistentVolumeClaim.[1]
A hostPath volume puts local directories on a directory of the node itself; support for mapping spark.local.dir to hostPath volumes arrived in Spark 3.0.0.[5] The Spark documentation warns that hostPath volumes have known security weaknesses and advises cluster administrators to restrict them with the Pod Security Admission controller.[1]
How do on-demand persistent volume claims work for shuffle?
Setting a volume's claimName option to OnDemand makes Spark create one PVC per executor, with the size and storage class from the sizeLimit and storageClass options.[1] Dynamic PVC creation and deletion for executors was added in Spark 3.1.0.[6] The Spark documentation recommends a PVC named spark-local-dir-* for jobs with large shuffles and sorts.[1]
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.options.claimName OnDemand
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.options.storageClass gp
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.options.sizeLimit 500Gi
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.mount.path /data
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.mount.readOnly false
Since Spark 4.2.0, the ExecutorPVCResizePlugin plugin can grow the storage request of an executor's spark-local-dir-* PVCs while the executor runs. It is controlled by spark.kubernetes.executor.pvc.resizeInterval (default 5 minutes), resizeThreshold (default 0.5) and resizeFactor (default 1.0), and requires a storage class that allows volume expansion.[1][3]
Which configuration keys control PVC reuse?
Three driver properties let on-demand PVCs outlive the executor that first used them.[3][1]
| Property | Added in | Default in 4.3.0 | Effect |
|---|---|---|---|
spark.kubernetes.driver.ownPersistentVolumeClaim |
3.2.0 | true | The driver pod, not the executor pod, owns on-demand PVCs |
spark.kubernetes.driver.reusePersistentVolumeClaim |
3.2.0 | true | The driver gives PVCs of deleted executors to new executors; requires driver ownership |
spark.kubernetes.driver.waitToReusePersistentVolumeClaim |
3.4.0 | false | The driver holds back new executors while it already owns as many PVCs as the job may have; requires both settings above |
The first two properties defaulted to false when they were introduced. Since Spark 3.4, the driver owns PVCs and tries to reuse those not attached to live executors; setting both properties to false restores the earlier behaviour.[7] A pod in Terminating state has not yet released its PVCs, so the total number of PVCs can exceed the number of running executors.[3]
What is KubernetesLocalDiskShuffleDataIO?
org.apache.spark.shuffle.KubernetesLocalDiskShuffleDataIO is a built-in shuffle storage plugin that recovers shuffle data from reused PVCs, so a new executor that mounts a reused PVC tries to recover the shuffle data that dead executors left in its local directories.[1][8] It was added in Spark 3.2.0 under SPARK-35593 and requires spark.kubernetes.driver.reusePersistentVolumeClaim=true.[9][10]
The documented setup mounts the PVC at a path such as /data/spark-x/executor-x and sets spark.shuffle.sort.io.plugin.class to the plugin class. The documentation also suggests enabling spark.kubernetes.driver.waitToReusePersistentVolumeClaim.[1]
How does shuffle storage relate to dynamic allocation and decommissioning?
Dynamic allocation needs shuffle files to survive executor removal. On other cluster managers the external shuffle service can do this, but Spark on Kubernetes does not support it, so setting spark.shuffle.service.enabled to true is not an option there.[2] The remaining options are shuffle tracking (spark.dynamicAllocation.shuffleTracking.enabled), shuffle block migration through executor decommissioning, or a shuffle plugin whose driver components support reliable storage.[2][11]
Decommissioning and PVC reuse address different failures. Decommissioning copies shuffle blocks from an executor that is being shut down to other executors, or to spark.storage.decommission.fallbackStorage.path, before the pod ends.[11] PVC reuse with KubernetesLocalDiskShuffleDataIO recovers files after a pod is already gone, as long as its PVC survives.[1]
See also
- Shuffle
- Executor
- Executor decommissioning
- Spark Kubernetes pod template
- Spark on Kubernetes
- Kubernetes Operator for Apache Spark
References
- ↑ 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 1.14 1.15 Running Spark on Kubernetes (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 2.0 2.1 2.2 Job Scheduling (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 3.0 3.1 3.2 3.3 Config.scala (Kubernetes resource manager, v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SPARK-25262: Support tmpfs for local dirs in k8s. Apache Software Foundation JIRA.Retrieved 2026-11-23.
- ↑ SPARK-28042: Support mapping spark.local.dir to hostPath volume. Apache Software Foundation JIRA.Retrieved 2026-11-23.
- ↑ SPARK-32971: Support dynamic PVC creation/deletion for K8s executors. Apache Software Foundation JIRA.Retrieved 2026-11-23.
- ↑ Migration Guide: Spark Core (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ KubernetesLocalDiskShuffleExecutorComponents.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ KubernetesLocalDiskShuffleDataIO.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SPARK-35593: Support shuffle data recovery on the reused PVCs. Apache Software Foundation JIRA.Retrieved 2026-11-23.
- ↑ 11.0 11.1 Spark Configuration (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.