Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit e600a07

Browse files
authored
Merge pull request #451 from kimoonkim/override-service-account
Support service account override
2 parents dca9b04 + 7959fc5 commit e600a07

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

docs/running-on-kubernetes.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ cluster, you may setup a test cluster on your local machine using
1717
* You must have appropriate permissions to create and list [pods](https://kubernetes.io/docs/user-guide/pods/),
1818
[ConfigMaps](https://kubernetes.io/docs/tasks/configure-pod-container/configmap/) and
1919
[secrets](https://kubernetes.io/docs/concepts/configuration/secret/) in your cluster. You can verify that
20-
you can list these resources by running `kubectl get pods` `kubectl get configmap`, and `kubectl get secrets` which
20+
you can list these resources by running `kubectl get pods`, `kubectl get configmap`, and `kubectl get secrets` which
2121
should give you a list of pods and configmaps (if any) respectively.
22+
* The service account or credentials used by the driver pods must have appropriate permissions
23+
as well for editing pod spec.
2224
* You must have a spark distribution with Kubernetes support. This may be obtained from the
2325
[release tarball](https://github.com/apache-spark-on-k8s/spark/releases) or by
2426
[building Spark with Kubernetes support](../resource-managers/kubernetes/README.md#building-spark-with-kubernetes-support).
@@ -107,6 +109,18 @@ Finally, notice that in the above example we specify a jar with a specific URI w
107109
the location of the example jar that is already in the Docker image. Using dependencies that are on your machine's local
108110
disk is discussed below.
109111

112+
When Kubernetes [RBAC](https://kubernetes.io/docs/admin/authorization/rbac/) is enabled,
113+
the `default` service account used by the driver may not have appropriate pod `edit` permissions
114+
for launching executor pods. We recommend to add another service account, say `spark`, with
115+
the necessary privilege. For example:
116+
117+
kubectl create serviceaccount spark
118+
kubectl create clusterrolebinding spark-edit --clusterrole edit \
119+
--serviceaccount default:spark --namespace default
120+
121+
With this, one can add `--conf spark.kubernetes.authenticate.driver.serviceAccountName=spark` to
122+
the spark-submit command line above to specify the service account to use.
123+
110124
## Dependency Management
111125

112126
Application dependencies that are being submitted from your machine need to be sent to a **resource staging server**

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/kubernetes/submit/submitsteps/DriverKubernetesCredentialsStep.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ private[spark] class DriverKubernetesCredentialsStep(
4444
s"$APISERVER_AUTH_DRIVER_MOUNTED_CONF_PREFIX.$CLIENT_CERT_FILE_CONF_SUFFIX")
4545
private val maybeMountedCaCertFile = submissionSparkConf.getOption(
4646
s"$APISERVER_AUTH_DRIVER_MOUNTED_CONF_PREFIX.$CA_CERT_FILE_CONF_SUFFIX")
47+
private val driverServiceAccount = submissionSparkConf.get(KUBERNETES_SERVICE_ACCOUNT_NAME)
4748

4849
override def configureDriver(driverSpec: KubernetesDriverSpec): KubernetesDriverSpec = {
4950
val driverSparkConf = driverSpec.driverSparkConf.clone()
@@ -81,7 +82,16 @@ private[spark] class DriverKubernetesCredentialsStep(
8182
.endVolume()
8283
.endSpec()
8384
.build()
84-
}.getOrElse(driverSpec.driverPod)
85+
}.getOrElse(
86+
driverServiceAccount.map { account =>
87+
new PodBuilder(driverSpec.driverPod)
88+
.editOrNewSpec()
89+
.withServiceAccount(account)
90+
.withServiceAccountName(account)
91+
.endSpec()
92+
.build()
93+
}.getOrElse(driverSpec.driverPod)
94+
)
8595
val driverContainerWithMountedSecretVolume = kubernetesCredentialsSecret.map { secret =>
8696
new ContainerBuilder(driverSpec.driverContainer)
8797
.addNewVolumeMount()

0 commit comments

Comments
 (0)