<p>So now that k8s is integrated directly with spark in 2.3 my spark submit from the console executes correctly on a kuberenetes master without any spark master pods running, spark handles all the k8s details:</p>

<pre><code>spark-submit \
  --deploy-mode cluster \
  --class com.app.myApp \
  --master k8s://https://myCluster.com \
  --conf spark.kubernetes.authenticate.driver.serviceAccountName=spark \
  --conf spark.app.name=myApp \
  --conf spark.executor.instances=10 \
  --conf spark.kubernetes.container.image=myImage \
  local:///myJar.jar
</code></pre>

<p>What I am trying to do is do a spark-submit via AWS lambda to my k8s cluster. Previously I used the command via the spark master REST API directly (without kubernetes):</p>

<pre><code>request = requests.Request(
    'POST',
    "http://&lt;master-ip&gt;:6066/v1/submissions/create",
    data=json.dumps(parameters))
prepared = request.prepare()
session = requests.Session()
response = session.send(prepared)
</code></pre>

<p>And it worked. Now I want to integrate Kubernetes and do it similarly where I submit an API request to my kubernetes cluster from python and have spark handle all the k8s details, ideally something like:</p>

<pre><code>request = requests.Request(
    'POST',
    "k8s://https://myK8scluster.com:443",
    data=json.dumps(parameters))
</code></pre>

<p>Is it possible in the Spark 2.3/Kubernetes integration?</p>

<p>I afraid that is impossible for Spark 2.3, if you using native Kubernetes support.</p>

<p>Based on description from <a href="https://spark.apache.org/docs/latest/running-on-kubernetes.html" rel="nofollow noreferrer">deployment instruction</a>, submission process container several steps:</p>

<ol>
<li>Spark creates a Spark driver running within a Kubernetes pod.</li>
<li>The driver creates executors which are also running within Kubernetes pods and connects to them, and executes application code.</li>
<li>When the application completes, the executor pods terminate and are cleaned up, but the driver pod persists logs and remains in “completed” state in the Kubernetes API until it’s eventually garbage collected or manually cleaned up.</li>
</ol>

<p>So, in fact, you have no place to submit a job until you starting a submission process, which will launch a first Spark's pod (driver) for you. And after application completes, everything terminated.</p>

<p>Because of running a fat container on AWS Lambda is not a best solution, and also because if is not way to run any commands in container itself (is is possible, but with hack, here is <a href="https://github.com/jacov/lambda-bash" rel="nofollow noreferrer">blueprint</a> about executing Bash inside an AWS Lambda) the simplest way is to write some small custom service, which will work on machine outside of AWS Lambda and provide REST interface between your application and <code>spark-submit</code> utility. I don't see any other ways to make it without a pain.</p>
