apache/spark
resource-managers
The resource-managers/ directory holds out-of-core cluster-manager integrations. The
in-tree built-in modes (local, standalone) live in core/; YARN and Kubernetes are big
enough to warrant their own modules.
Modes overview
| Mode | Source | Notes |
|---|---|---|
| Local | core/.../scheduler/local/ |
Single JVM, threads as executors. Useful for tests. |
| Standalone | core/.../deploy/{master,worker,client}/ |
Spark's own daemons. Two-process cluster manager. |
| YARN | resource-managers/yarn/ |
Hadoop's cluster manager. |
| Kubernetes | resource-managers/kubernetes/ |
K8s pods as executors. |
| Mesos | (removed in Spark 3.5) | No longer in the tree. |
All four cluster-manager backends implement SchedulerBackend
(core/.../scheduler/SchedulerBackend.scala) and CoarseGrainedSchedulerBackend.
YARN
resource-managers/yarn/
src/main/scala/org/apache/spark/deploy/yarn/
ApplicationMaster.scala - the AM running inside YARN
Client.scala - the spark-submit-side YARN client
YarnAllocator.scala - asks YARN for executor containers
YarnRMClient.scala
YarnSchedulerBackend.scala
security/ - Kerberos token providers
src/main/scala/org/apache/spark/scheduler/cluster/
YarnClusterManager.scala
YarnClusterScheduler.scala
YarnClusterSchedulerBackend.scala
YarnClientSchedulerBackend.scalaKey flow:
Client.scalapackages and submits the app to the YARN ResourceManager.- The RM launches
ApplicationMaster.scalain a container. - The AM negotiates with
YarnAllocatorfor executor containers. - Each container starts a
CoarseGrainedExecutorBackend(defined incore/) that registers back with the driver. - Hadoop delegation tokens are managed by token providers under
resource-managers/yarn/.../security/and renewed periodically.
YARN is built with -Pyarn. There are no YARN-specific Python dependencies; this is JVM-only.
Kubernetes
resource-managers/kubernetes/
core/ - The K8s scheduler backend
src/main/scala/org/apache/spark/deploy/k8s/
Config.scala
KubernetesUtils.scala
submit/ - spark-submit-side K8s client (KubernetesClientApplication)
features/ - per-pod features (volumes, env, secrets, ...)
scheduler/cluster/k8s/ - KubernetesClusterSchedulerBackend, ExecutorPodsAllocator
integration-tests/ - end-to-end tests on Minikube / kindKey concepts:
- The driver runs as either a K8s pod ("cluster mode") or a local process ("client mode").
ExecutorPodsAllocatormaintains the desired executor count by creating pods.KubernetesFeatureConfigSteps contribute pieces of the pod spec (MountVolumesFeatureStep,EnvSecretsFeatureStep,LocalDirsFeatureStep, ...).- Persistent volume claims can be reused across executor restarts via
OnDemandVolumes. - A K8s scheduler plugin can dynamically resize executors without restarting them.
Build with -Pkubernetes. The integration-tests subproject runs on Minikube or kind and is
not part of the standard CI matrix.
Standalone (in core)
core/.../deploy/master/ is the Master daemon (an Apache 2 cluster manager). It tracks
registered Workers and assigns executors to applications when they connect via
StandaloneAppClient. Workers run on each cluster node and launch executors via
org.apache.spark.deploy.worker.ExecutorRunner.
The standalone deploy mode is the simplest cluster setup: no Hadoop, no Kubernetes, just two Java processes per node.
Dynamic allocation
Cross-cutting work that all cluster-manager backends share:
ExecutorAllocationManager(core/.../ExecutorAllocationManager.scala) decides when to request and release executors based on pending tasks and idleness.ExecutorAllocationClientis the interface backends implement (the YARN, K8s, and standalone backends all do).- Decommissioning - graceful shutdown that migrates blocks - is implemented by
BlockManagerDecommissioner(core/.../storage/BlockManagerDecommissioner.scala) andFallbackStorage(core/.../storage/FallbackStorage.scala).
Integration points
- All backends register with
TaskSchedulerImpland useCoarseGrainedSchedulerBackendas the base class for the network protocol with executors. - Both YARN and K8s back-ends interact with
BlockManagerto migrate shuffle and cache blocks during graceful decommissioning. - YARN reads Hadoop config via
core/.../deploy/SparkHadoopUtil.scala. Kubernetes uses the fabric8 Kubernetes client (io.fabric8:kubernetes-client).
Entry points for modification
- Add a feature to the K8s pod spec: implement a new
KubernetesFeatureConfigStepand register it inKubernetesDriverBuilder/KubernetesExecutorBuilder. - Add a new YARN credential provider: implement
ServiceCredentialProviderand register viaMETA-INF/services/. - Tweak dynamic allocation behavior: most knobs are in
core/.../internal/config/DynamicAllocation.scala. Look atcore/.../ExecutorAllocationManager.scalafor the decision logic.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.