<p>I don't know if this is already answered in SO but I couldn't find a solution to my problem.</p>

<p>I have an IPython notebook running in a docker container in Google Container Engine, the container is based on this image <a href="https://github.com/jupyter/docker-stacks/tree/master/all-spark-notebook" rel="noreferrer">jupyter/all-spark-notebook</a></p>

<p>I have also a spark cluster created with <a href="https://cloud.google.com/dataproc/" rel="noreferrer">google cloud dataproc</a></p>

<p>Spark master and the notebook are running in <strong>different VMs</strong> but in the <strong>same region and zone</strong>.</p>

<p>My problem is that I'm trying to connect to the spark master from the IPython notebook but without success. I use this snippet of code in my python notebook</p>

<pre><code>import pyspark
conf = pyspark.SparkConf()
conf.setMaster("spark://&lt;spark-master-ip or spark-master-hostname&gt;:7077")
</code></pre>

<p>I just started working with spark, so I'm sure I'm missing something (authentication, security ...), </p>

<p>What I found over there is connecting a local browser over an <a href="https://cloud.google.com/dataproc/cluster-web-interfaces" rel="noreferrer">SSH tunnel</a></p>

<p>Somebody already did this kind of set up?</p>

<p>Thank you in advance</p>

<p>Dataproc runs <a href="http://spark.apache.org/docs/latest/running-on-yarn.html" rel="noreferrer">Spark on YARN</a>, so you need to set master to 'yarn-client'. You also need to point Spark at your YARN ResourceManager, which requires a under-documented SparkConf -> Hadoop Configuration conversion. You also have to tell Spark about HDFS on the cluster, so it can stage resources for YARN. You could use Google Cloud Storage instead of HDFS, if you baked <a href="https://cloud.google.com/hadoop/google-cloud-storage-connector" rel="noreferrer">The Google Cloud Storage Connector for Hadoop</a> into your image.</p>

<p>Try:</p>

<pre><code>import pyspark
conf = pyspark.SparkConf()
conf.setMaster('yarn-client')
conf.setAppName('My Jupyter Notebook')

# 'spark.hadoop.foo.bar' sets key 'foo.bar' in the Hadoop Configuaration.
conf.set('spark.hadoop.yarn.resourcemanager.address', '&lt;spark-master-hostname&gt;')
conf.set('spark.hadoop.fs.default.name', 'hdfs://&lt;spark-master-hostname&gt;/')

sc = pyspark.SparkContext(conf=conf)
</code></pre>

<p>For a more permanent config, you could bake these into a local file 'core-site.xml' as described <a href="https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/SingleCluster.html#Configuration" rel="noreferrer">here</a>, place that in a local directory, and set HADOOP_CONF_DIR to that directory in your environment.</p>

<p>It's also worth noting that while being in the same Zone is important for performance, it is being in the same <a href="https://cloud.google.com/compute/docs/networking#networks" rel="noreferrer">Network</a> and allowing TCP between internal IP addresses in that network that allows your VMs to communicate. If you are using the <code>default</code> network, then the <code>default-allow-internal</code> <a href="https://cloud.google.com/compute/docs/networking#firewall_rules" rel="noreferrer">firewall rule</a>, should be sufficient.</p>

<p>Hope that helps.</p>
