<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Spark_Kubernetes_pod_template</id>
	<title>Spark Kubernetes pod template - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Spark_Kubernetes_pod_template"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Spark_Kubernetes_pod_template&amp;action=history"/>
	<updated>2026-12-06T00:13:49Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=Spark_Kubernetes_pod_template&amp;diff=188&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@7c9abaa</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Spark_Kubernetes_pod_template&amp;diff=188&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:54Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = Spark Kubernetes pod template&lt;br /&gt;
| also_known_as   = Pod template file, driver pod template, executor pod template&lt;br /&gt;
| field           = Cluster resource management&lt;br /&gt;
| introduced      = Apache Spark 3.0.0&lt;br /&gt;
| key_parts       = &amp;lt;code&amp;gt;spark.kubernetes.driver.podTemplateFile&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.kubernetes.executor.podTemplateFile&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;podTemplateContainerName&amp;lt;/code&amp;gt;&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Spark on Kubernetes]], [[Executor]], [[Spark Kubernetes shuffle storage]], [[Executor decommissioning]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/running-on-kubernetes.md and resource-managers/kubernetes/core/.../deploy/k8s/Config.scala), SPARK-24434 and the Kubernetes sidecar containers page}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], a &amp;#039;&amp;#039;&amp;#039;Kubernetes pod template&amp;#039;&amp;#039;&amp;#039; is a YAML or JSON pod specification that Spark uses as the starting point when it builds the driver pod or the executor pods of an application on Kubernetes.&amp;lt;ref name=&amp;quot;k8s&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/running-on-kubernetes.html |title=Running Spark on Kubernetes (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A pod template sets pod fields that have no Spark configuration property, such as tolerations, security contexts, priority classes and extra containers. Spark still overwrites a fixed list of fields, so the template is a base that Spark completes rather than a final pod definition.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; The feature is part of [[Spark on Kubernetes]] and is also used by the [[Kubernetes Operator for Apache Spark]], which runs applications on the same scheduler backend.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which configuration keys control a pod template? ==&lt;br /&gt;
Four Spark properties control pod templates. All four were added in Apache Spark 3.0.0 and have no default value.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;config&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/Config.scala |title=Config.scala (Kubernetes resource manager, v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;jira24434&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-24434 |title=SPARK-24434: Support user-specified driver and executor pod templates |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Property !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.kubernetes.driver.podTemplateFile&amp;lt;/code&amp;gt; || File with the template for the driver pod&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.kubernetes.executor.podTemplateFile&amp;lt;/code&amp;gt; || File with the template for every executor pod&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.kubernetes.driver.podTemplateContainerName&amp;lt;/code&amp;gt; || Name of the container in the driver template that becomes the Spark driver container&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.kubernetes.executor.podTemplateContainerName&amp;lt;/code&amp;gt; || Name of the container in the executor template that becomes the Spark executor container&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The template files must be readable by the &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; process, and the Spark documentation shows them read from object storage, for example &amp;lt;code&amp;gt;s3a://bucket/executor.yml&amp;lt;/code&amp;gt;. In cluster mode Spark mounts the executor template into the driver pod as a volume, because the driver creates the executor pods.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark does not validate a template after parsing it. Validation is left to the Kubernetes API server, so an invalid field shows up as a rejected pod creation rather than a Spark error.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does Spark choose the Spark container in a template? ==&lt;br /&gt;
A pod template can list several containers. Spark uses the container named by &amp;lt;code&amp;gt;spark.kubernetes.driver.podTemplateContainerName&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;spark.kubernetes.executor.podTemplateContainerName&amp;lt;/code&amp;gt; as the basis for the driver or executor container. If the property is unset, or names a container that does not exist, Spark takes the first container in the list.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark changes only the driver or executor container. Every other container in the template is passed to Kubernetes unchanged.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; If the template does not name the Spark container, Spark calls it &amp;lt;code&amp;gt;spark-kubernetes-driver&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;spark-kubernetes-executor&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which pod template fields does Spark override? ==&lt;br /&gt;
The Spark documentation lists the fields that Spark always sets or adds to, whatever the template says.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Level !! Field !! What Spark does&lt;br /&gt;
|-&lt;br /&gt;
| Pod metadata || &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; || Sets the driver pod name from &amp;lt;code&amp;gt;spark.kubernetes.driver.pod.name&amp;lt;/code&amp;gt;; executor pod names are not taken from the template&lt;br /&gt;
|-&lt;br /&gt;
| Pod metadata || &amp;lt;code&amp;gt;namespace&amp;lt;/code&amp;gt; || Replaced by &amp;lt;code&amp;gt;spark.kubernetes.namespace&amp;lt;/code&amp;gt; for driver and executors&lt;br /&gt;
|-&lt;br /&gt;
| Pod metadata || &amp;lt;code&amp;gt;labels&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;annotations&amp;lt;/code&amp;gt; || Keeps the template&amp;#039;s entries and adds those from &amp;lt;code&amp;gt;spark.kubernetes.{driver,executor}.label.*&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.annotation.*&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Pod spec || &amp;lt;code&amp;gt;restartPolicy&amp;lt;/code&amp;gt; || Always &amp;lt;code&amp;gt;Never&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Pod spec || &amp;lt;code&amp;gt;nodeSelector&amp;lt;/code&amp;gt; || Adds selectors from &amp;lt;code&amp;gt;spark.kubernetes.node.selector.*&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Pod spec || &amp;lt;code&amp;gt;imagePullSecrets&amp;lt;/code&amp;gt; || Adds secrets from &amp;lt;code&amp;gt;spark.kubernetes.container.image.pullSecrets&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Pod spec || &amp;lt;code&amp;gt;serviceAccount&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;serviceAccountName&amp;lt;/code&amp;gt; || Driver only, and only when &amp;lt;code&amp;gt;spark.kubernetes.authenticate.driver.serviceAccountName&amp;lt;/code&amp;gt; is set and no driver credentials are mounted&lt;br /&gt;
|-&lt;br /&gt;
| Pod spec || &amp;lt;code&amp;gt;volumes&amp;lt;/code&amp;gt; || Adds volumes from &amp;lt;code&amp;gt;spark.kubernetes.{driver,executor}.volumes.*&amp;lt;/code&amp;gt; plus the volumes that carry the Spark configuration and template files&lt;br /&gt;
|-&lt;br /&gt;
| Spark container || &amp;lt;code&amp;gt;image&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;imagePullPolicy&amp;lt;/code&amp;gt; || Set from &amp;lt;code&amp;gt;spark.kubernetes.{driver,executor}.container.image&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.kubernetes.container.image.pullPolicy&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Spark container || &amp;lt;code&amp;gt;resources&amp;lt;/code&amp;gt; || CPU from &amp;lt;code&amp;gt;spark.{driver,executor}.cores&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.kubernetes.{driver,executor}.limit.cores&amp;lt;/code&amp;gt;; memory request and limit from memory plus memory overhead&lt;br /&gt;
|-&lt;br /&gt;
| Spark container || &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;volumeMounts&amp;lt;/code&amp;gt; || Adds environment variables and mounts from the Spark configuration&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Fields not in this list, such as &amp;lt;code&amp;gt;tolerations&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;affinity&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;priorityClassName&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;securityContext&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;initContainers&amp;lt;/code&amp;gt;, are taken from the template as written.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; The documentation uses &amp;lt;code&amp;gt;priorityClassName&amp;lt;/code&amp;gt; in a template as its example of priority scheduling.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Resources in a template apply only to the default resource profile. With stage-level scheduling, custom ResourceProfiles do not inherit resources from the template file, so they must declare every resource they need.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is a pod template commonly used for? ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Scheduling.&amp;#039;&amp;#039;&amp;#039; Node selectors can be set without a template: &amp;lt;code&amp;gt;spark.kubernetes.node.selector.[labelKey]&amp;lt;/code&amp;gt; (since Spark 2.3.0) applies to driver and executors, and the driver-only and executor-only variants were added in Spark 3.3.0.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; Tolerations and affinity rules have no Spark property and are set through the template.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Volumes.&amp;#039;&amp;#039;&amp;#039; Spark properties can mount &amp;lt;code&amp;gt;hostPath&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emptyDir&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;nfs&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;persistentVolumeClaim&amp;lt;/code&amp;gt; volumes.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; Other volume types, such as a ConfigMap or projected volume, are declared in the template. Volumes for shuffle and spill data are described in [[Spark Kubernetes shuffle storage]].&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Sidecars.&amp;#039;&amp;#039;&amp;#039; A template can add containers next to the Spark container, for example a log shipper. Kubernetes treats an init container with &amp;lt;code&amp;gt;restartPolicy: Always&amp;lt;/code&amp;gt; as a native sidecar; it is stable since Kubernetes 1.33, and the kubelet waits until the main container has stopped before it terminates the sidecar.&amp;lt;ref name=&amp;quot;sidecar&amp;quot;&amp;gt;{{Cite web |url=https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/ |title=Sidecar Containers |publisher=The Kubernetes Authors |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark 4.3.0 documents Kubernetes 1.34 or later as a prerequisite.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Security contexts.&amp;#039;&amp;#039;&amp;#039; The Spark images built from the project Dockerfiles run as UID 185. The documentation names the pod template as the way to add a security context with &amp;lt;code&amp;gt;runAsUser&amp;lt;/code&amp;gt; that overrides the image&amp;#039;s user.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; Apache Spark 4.3.0 added &amp;lt;code&amp;gt;spark.kubernetes.securityContext.allowPrivilegeEscalation&amp;lt;/code&amp;gt; (default false) and driver and executor variants, which set the &amp;lt;code&amp;gt;allowPrivilegeEscalation&amp;lt;/code&amp;gt; field of the Spark containers.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
An executor pod template that pins executors to a tainted node pool, runs them as a non-root user and adds a native sidecar. The &amp;lt;code&amp;gt;image&amp;lt;/code&amp;gt; value is replaced by Spark.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;yaml&amp;quot;&amp;gt;&lt;br /&gt;
apiVersion: v1&lt;br /&gt;
kind: Pod&lt;br /&gt;
spec:&lt;br /&gt;
  nodeSelector:&lt;br /&gt;
    pool: spark&lt;br /&gt;
  tolerations:&lt;br /&gt;
  - key: dedicated&lt;br /&gt;
    operator: Equal&lt;br /&gt;
    value: spark&lt;br /&gt;
    effect: NoSchedule&lt;br /&gt;
  securityContext:&lt;br /&gt;
    runAsUser: 185&lt;br /&gt;
    runAsNonRoot: true&lt;br /&gt;
  initContainers:&lt;br /&gt;
  - name: log-shipper&lt;br /&gt;
    image: example.org/log-shipper:1.0&lt;br /&gt;
    restartPolicy: Always&lt;br /&gt;
  containers:&lt;br /&gt;
  - name: spark-executor&lt;br /&gt;
    image: will-be-overwritten&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
spark.kubernetes.executor.podTemplateFile           s3a://bucket/executor.yml&lt;br /&gt;
spark.kubernetes.executor.podTemplateContainerName  spark-executor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark on Kubernetes]]&lt;br /&gt;
* [[Kubernetes Operator for Apache Spark]]&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Spark Kubernetes shuffle storage]]&lt;br /&gt;
* [[Executor decommissioning]]&lt;br /&gt;
* [[Apache Spark]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>