<p>I'm creating a container with a connection to a cloudsql database, when I run the image with kubernetes It does not have an external IP that I can use to allow the new image to connect to the database. But as this is part of the init configuration I can't wait to know what is the public IP to add to the whitelist databases.</p>

<p>I know that are ways to connect a database through services in the same cluster, but I can't figure out how to connect with the cloudsql provided by google.</p>

<p>There are two ways to solve that:</p>

<p>The first option is to use a cloudsql proxy using the instructions available in: <a href="https://cloud.google.com/sql/docs/sql-proxy" rel="noreferrer">https://cloud.google.com/sql/docs/sql-proxy</a> </p>

<p>In your docker image you need to ensure that fuse is available in your installation, in wasn't my case (using a ubuntu:trusty-20160119 as base image). If you need to able that, then use the following steps in your Dockerfile:</p>

<pre><code># install fusermount
# RUN apt-get install build-essential -y
# RUN wget https://github.com/libfuse/libfuse/releases/download/fuse_2_9_5/fuse-2.9.5.tar.gz
# RUN tar -xzvf fuse-2.9.5.tar.gz
# RUN cd fuse-2.9.5 &amp;&amp; ./configure &amp;&amp; make -j8 &amp;&amp; make install
</code></pre>

<p>Then at the startup of your container you must create a script that open the socket as described in <a href="https://cloud.google.com/sql/docs/sql-proxy#example_proxy_invocations_and_connection_strings" rel="noreferrer">https://cloud.google.com/sql/docs/sql-proxy#example_proxy_invocations_and_connection_strings</a>.</p>

<p>The second way is just to allow the ips from the nodes that support the kubernetes cluster in the whitelist for the cloudsql. </p>

<p>I prefer the first option, because it works in any machine I deploy the image and I don't need to care about to add or remove ips if I need to deliver more nodes in the kubernetes cluster.</p>
