<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Unable to run spark-shell command with k8s as master in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Unable-to-run-spark-shell-command-with-k8s-as-master/m-p/404627#M252345</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/95925"&gt;@spserd&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Looking at your issue with Spark on Kubernetes, I see a clear difference between the client and cluster deployment modes that's causing the "&lt;FONT color="#FF0000"&gt;system&lt;/FONT&gt;" authentication problem. the issue is when running in client mode with &lt;FONT color="#FF0000"&gt;spark-shell,&lt;/FONT&gt; you're encountering an authorization issue where Spark is trying to create executor pods as "system&lt;SPAN&gt;" instead of using your service account "spark-sa", despite providing the token.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Possible Solution&lt;BR /&gt;For client mode, you need to add a specific configuration to tell Spark to use the token for executor pod creation&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-SPOILER&gt;--conf spark.kubernetes.authenticate.executor.serviceAccountName=spark-sa&lt;/LI-SPOILER&gt;&lt;P&gt;&lt;SPAN&gt;So your updated command should look like this&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-SPOILER&gt;./bin/spark-shell \&lt;BR /&gt;--master k8s://&lt;A href="https://my-k8s-cluster:6443" target="_blank"&gt;https://my-k8s-cluster:6443&lt;/A&gt; \&lt;BR /&gt;--deploy-mode client \&lt;BR /&gt;--name spark-shell-poc \&lt;BR /&gt;--conf spark.executor.instances=1 \&lt;BR /&gt;--conf spark.kubernetes.container.image=my-docker-hub/spark_poc:v1.4 \&lt;BR /&gt;--conf spark.kubernetes.container.image.pullPolicy=IfNotPresent \&lt;BR /&gt;--conf spark.kubernetes.namespace=dynx-center-resources \&lt;BR /&gt;--conf spark.driver.pod.name=dynx-spark-driver \&lt;BR /&gt;--conf spark.kubernetes.authenticate.driver.serviceAccountName=spark-sa \&lt;BR /&gt;--conf spark.kubernetes.authenticate.executor.serviceAccountName=spark-sa \&lt;BR /&gt;--conf spark.kubernetes.authenticate.submission.oauthToken=$K8S_TOKEN&lt;/LI-SPOILER&gt;&lt;P class="whitespace-pre-wrap break-words"&gt;The key is that in client mode, you need to explicitly configure the executor authentication because the driver is running outside the cluster and needs to delegate this permission.&lt;/P&gt;&lt;P class="whitespace-pre-wrap break-words"&gt;If this still doesn't work, ensure your service account has appropriate &lt;FONT color="#FF0000"&gt;ClusterRole bindings&lt;/FONT&gt; that allow it to create and manage pods in the specified namespace.&lt;/P&gt;&lt;P&gt;Happy hadooping&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 23 Mar 2025 11:42:32 GMT</pubDate>
    <dc:creator>Shelton</dc:creator>
    <dc:date>2025-03-23T11:42:32Z</dc:date>
    <item>
      <title>Unable to run spark-shell command with k8s as master</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Unable-to-run-spark-shell-command-with-k8s-as-master/m-p/401807#M251316</link>
      <description>&lt;P&gt;Hello all - I'm trying to run the below spark-shell command from the bin directory of spark 3.4.3 extracted location. I specified the master as my Kubernetes environment as I'd like my executors to run on the k8s environment.&lt;/P&gt;&lt;P&gt;I created a service account with all necessary permissions.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="s1"&gt;# kubectl auth can-i create pod --as=system:serviceaccount:my-namespace:spark-sa -n my-namespace&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="s1"&gt;yes&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Command:&lt;/P&gt;&lt;PRE&gt;&lt;EM&gt;#&amp;nbsp;export K8S_TOKEN=$(kubectl get secrets -o jsonpath="{.items[?(@.metadata.annotations['kubernetes\.io/service-account\.name']=='spark-sa')].data.token}"|base64 --decode)&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;# ./bin/spark-shell \&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;--master k8s://https://my-k8s-cluster:6443 \ &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;--deploy-mode client \ &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;--name spark-shell-poc \ &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;--conf spark.executor.instances=1 \ &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;--conf spark.kubernetes.container.image=my-docker-hub/spark_poc:v1.4 \ &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;--conf spark.kubernetes.container.image.pullPolicy=IfNotPresent \ &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;--conf spark.kubernetes.namespace=dynx-center-resources \ &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;--conf spark.driver.pod.name=dynx-spark-driver \ &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;--conf spark.kubernetes.authenticate.driver.serviceAccountName=spark-sa \ &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;--conf spark.kubernetes.authenticate.submission.oauthToken=$K8S_TOKEN&lt;/EM&gt;&lt;/PRE&gt;&lt;P&gt;Even though I specified the service account to use and its token, it always ends up in using 'system:anonymous' user to create pods in my k8s environment and because of that I get the below error (snippet from a huge stack trace).&lt;/P&gt;&lt;PRE&gt;&lt;EM&gt;25/02/06 14:36:32 WARN ExecutorPodsSnapshotsStoreImpl: Exception when notifying snapshot subscriber.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: POST at: https://my-k8s-cluster:6443/api/v1/namespaces/dynx-center-resources/pods. Message: pods is forbidden: User "system:anonymous" cannot create resource "pods" in API group "" in the namespace "dynx-center-resources". Received status: Status(apiVersion=v1, code=403, details=StatusDetails(causes=[], group=null, kind=pods, name=null, retryAfterSeconds=null, uid=null, additionalProperties={}), kind=Status, message=pods is forbidden: User "system:anonymous" cannot create resource "pods" in API group "" in the namespace "dynx-center-resources", metadata=ListMeta(_continue=null, remainingItemCount=null, resourceVersion=null, selfLink=null, additionalProperties={}), reason=Forbidden, status=Failure, additionalProperties={}).&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at io.fabric8.kubernetes.client.KubernetesClientException.copyAsCause(KubernetesClientException.java:238)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.waitForResult(OperationSupport.java:538)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.handleResponse(OperationSupport.java:558)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.handleCreate(OperationSupport.java:349)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.handleCreate(BaseOperation.java:711)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.handleCreate(BaseOperation.java:93)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at io.fabric8.kubernetes.client.dsl.internal.CreateOnlyResourceOperation.create(CreateOnlyResourceOperation.java:42)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.create(BaseOperation.java:1113)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.create(BaseOperation.java:93)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at org.apache.spark.scheduler.cluster.k8s.ExecutorPodsAllocator.$anonfun$requestNewExecutors$1(ExecutorPodsAllocator.scala:440)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:158)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at org.apache.spark.scheduler.cluster.k8s.ExecutorPodsAllocator.requestNewExecutors(ExecutorPodsAllocator.scala:417)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at org.apache.spark.scheduler.cluster.k8s.ExecutorPodsAllocator.$anonfun$onNewSnapshots$36(ExecutorPodsAllocator.scala:370)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at org.apache.spark.scheduler.cluster.k8s.ExecutorPodsAllocator.$anonfun$onNewSnapshots$36$adapted(ExecutorPodsAllocator.scala:363)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:62)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:55)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:49)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at org.apache.spark.scheduler.cluster.k8s.ExecutorPodsAllocator.onNewSnapshots(ExecutorPodsAllocator.scala:363)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at org.apache.spark.scheduler.cluster.k8s.ExecutorPodsAllocator.$anonfun$start$3(ExecutorPodsAllocator.scala:134)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at org.apache.spark.scheduler.cluster.k8s.ExecutorPodsAllocator.$anonfun$start$3$adapted(ExecutorPodsAllocator.scala:134)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at org.apache.spark.scheduler.cluster.k8s.ExecutorPodsSnapshotsStoreImpl$SnapshotsSubscriber.org$apache$spark$scheduler$cluster$k8s$ExecutorPodsSnapshotsStoreImpl$SnapshotsSubscriber$$processSnapshotsInternal(ExecutorPodsSnapshotsStoreImpl.scala:143)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at org.apache.spark.scheduler.cluster.k8s.ExecutorPodsSnapshotsStoreImpl$SnapshotsSubscriber.processSnapshots(ExecutorPodsSnapshotsStoreImpl.scala:131)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at org.apache.spark.scheduler.cluster.k8s.ExecutorPodsSnapshotsStoreImpl.$anonfun$addSubscriber$1(ExecutorPodsSnapshotsStoreImpl.scala:85)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;at java.base/java.lang.Thread.run(Thread.java:840)&lt;/EM&gt;&lt;/PRE&gt;&lt;P&gt;As a part of troubleshooting, I tried running the below curl command using the same service account user token and got the results.&lt;/P&gt;&lt;PRE&gt;&lt;I&gt;curl -X GET https://my-k8s-cluster:6443/api --header "Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjdWOXgwTjdIeUdCTGx2eEItOXZ3eDlSV1I1UXd1d0MtTXJENFBhXzNDTTgifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkeW54LWNlbnRlci1yZXNvdXJjZXMiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlY3JldC5uYW1lIjoic3Bhcmstc2EiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoic3Bhcmstc2EiLCJrdWJlcm5ldGVzxxxxxxxxxxxxxxxxxxxxxmMS03NzI5LTQ5OTAtYWZkOC1mYjZiNzU4ZDg5YzAiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6ZHlueC1jZW50ZXItcmVzb3VyY2VzOnNwYXJrLXNhIn0.TWAQYmu_N-N1gnZ1hYYn_wvavs9f9w33v0P0Kgchd1eETO8TpHlYS_JSt8jzWlX6C4JF293Q8VRk8p1Nx3zRdqjZnYWmMvJYCaq5mBAyvXAW8fXW_ZtQD7HJPUEUb2ZDXUz3b2XLgvJoWui8vhqZBYUev67YgHHRspgkwDbLrRIB1oRPbx_2osYMQW3tPxoThyzUqdvyBij3hjW-syrsp_sR1ir-78XzIZpkV2OBFds7u8vd0IqoWLOtmnZwdq1RKCKtFk292VfWSbN0HYJUs_aJUeaqLpekopZLfDM2U_GT0ImwBUOL2EILpb-K1xdWr4-Jv4qPsFBLFh31S2OMAg" --insecure&lt;/I&gt;&lt;BR /&gt;&lt;I&gt;{&lt;/I&gt;&lt;BR /&gt;&lt;I&gt;&amp;nbsp;"kind": "APIVersions",&lt;/I&gt;&lt;BR /&gt;&lt;I&gt;&amp;nbsp;"versions": [&lt;/I&gt;&lt;BR /&gt;&lt;I&gt;&amp;nbsp; &amp;nbsp;"v1"&lt;/I&gt;&lt;BR /&gt;&lt;I&gt;&amp;nbsp;],&lt;/I&gt;&lt;BR /&gt;&lt;I&gt;&amp;nbsp;"serverAddressByClientCIDRs": [&lt;/I&gt;&lt;BR /&gt;&lt;I&gt;&amp;nbsp; &amp;nbsp;{&lt;/I&gt;&lt;BR /&gt;&lt;I&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"clientCIDR": "0.0.0.0/0",&lt;/I&gt;&lt;BR /&gt;&lt;I&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"serverAddress": "10.14.3.19:6443"&lt;/I&gt;&lt;BR /&gt;&lt;I&gt;&amp;nbsp; &amp;nbsp;}&lt;/I&gt;&lt;BR /&gt;&lt;I&gt;&amp;nbsp;]&lt;/I&gt;&lt;BR /&gt;&lt;I&gt;}% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/I&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/PRE&gt;&lt;P&gt;However, if I run the &lt;EM&gt;spark-submit&lt;/EM&gt; command via &lt;EM&gt;cluster&lt;/EM&gt; deploy mode, it runs without any issue and produce the desired output.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;# ./bin/spark-submit \&lt;BR /&gt;--master k8s://https://my-k8s-cluster:6443 \&lt;BR /&gt;--deploy-mode cluster \&lt;BR /&gt;--name spark-poc \&lt;BR /&gt;--conf spark.executor.instances=2 \&lt;BR /&gt;--conf spark.kubernetes.container.image=my-docker-hub/spark_poc:v1.4 \&lt;BR /&gt;--conf spark.kubernetes.container.image.pullPolicy=IfNotPresent \&lt;BR /&gt;--conf spark.kubernetes.namespace=dynx-center-resources \&lt;BR /&gt;--conf spark.kubernetes.authenticate.driver.serviceAccountName=spark-sa \&lt;BR /&gt;--conf spark.kubernetes.authenticate.submission.oauthToken=$K8S_TOKEN \&lt;BR /&gt;--class org.apache.spark.examples.SparkPi \&lt;BR /&gt;local:///opt/spark/examples/jars/spark-examples_2.12-3.4.3.jar 1000&lt;/PRE&gt;&lt;P&gt;Not sure what I'm missing. Appreciate any help on this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2025 20:58:31 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Unable-to-run-spark-shell-command-with-k8s-as-master/m-p/401807#M251316</guid>
      <dc:creator>spserd</dc:creator>
      <dc:date>2025-02-10T20:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to run spark-shell command with k8s as master</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Unable-to-run-spark-shell-command-with-k8s-as-master/m-p/404627#M252345</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/95925"&gt;@spserd&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Looking at your issue with Spark on Kubernetes, I see a clear difference between the client and cluster deployment modes that's causing the "&lt;FONT color="#FF0000"&gt;system&lt;/FONT&gt;" authentication problem. the issue is when running in client mode with &lt;FONT color="#FF0000"&gt;spark-shell,&lt;/FONT&gt; you're encountering an authorization issue where Spark is trying to create executor pods as "system&lt;SPAN&gt;" instead of using your service account "spark-sa", despite providing the token.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Possible Solution&lt;BR /&gt;For client mode, you need to add a specific configuration to tell Spark to use the token for executor pod creation&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-SPOILER&gt;--conf spark.kubernetes.authenticate.executor.serviceAccountName=spark-sa&lt;/LI-SPOILER&gt;&lt;P&gt;&lt;SPAN&gt;So your updated command should look like this&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-SPOILER&gt;./bin/spark-shell \&lt;BR /&gt;--master k8s://&lt;A href="https://my-k8s-cluster:6443" target="_blank"&gt;https://my-k8s-cluster:6443&lt;/A&gt; \&lt;BR /&gt;--deploy-mode client \&lt;BR /&gt;--name spark-shell-poc \&lt;BR /&gt;--conf spark.executor.instances=1 \&lt;BR /&gt;--conf spark.kubernetes.container.image=my-docker-hub/spark_poc:v1.4 \&lt;BR /&gt;--conf spark.kubernetes.container.image.pullPolicy=IfNotPresent \&lt;BR /&gt;--conf spark.kubernetes.namespace=dynx-center-resources \&lt;BR /&gt;--conf spark.driver.pod.name=dynx-spark-driver \&lt;BR /&gt;--conf spark.kubernetes.authenticate.driver.serviceAccountName=spark-sa \&lt;BR /&gt;--conf spark.kubernetes.authenticate.executor.serviceAccountName=spark-sa \&lt;BR /&gt;--conf spark.kubernetes.authenticate.submission.oauthToken=$K8S_TOKEN&lt;/LI-SPOILER&gt;&lt;P class="whitespace-pre-wrap break-words"&gt;The key is that in client mode, you need to explicitly configure the executor authentication because the driver is running outside the cluster and needs to delegate this permission.&lt;/P&gt;&lt;P class="whitespace-pre-wrap break-words"&gt;If this still doesn't work, ensure your service account has appropriate &lt;FONT color="#FF0000"&gt;ClusterRole bindings&lt;/FONT&gt; that allow it to create and manage pods in the specified namespace.&lt;/P&gt;&lt;P&gt;Happy hadooping&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Mar 2025 11:42:32 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Unable-to-run-spark-shell-command-with-k8s-as-master/m-p/404627#M252345</guid>
      <dc:creator>Shelton</dc:creator>
      <dc:date>2025-03-23T11:42:32Z</dc:date>
    </item>
  </channel>
</rss>

