<p>I have been exploring ways to securely connect to Google Cloud SQL database. We use Google Kubernetes Engine for deployment of our Java Spring application.</p>

<p>So, <a href="https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine" rel="nofollow noreferrer">https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine</a> mentions of two methods to connect to cloud sql from kubernetes. We cannot use private IP method since we do not have VPC native clusters. So we choose Cloud SQL Proxy docker image as the connection medium.</p>

<p>Then, considering <a href="https://cloud.google.com/sql/docs/postgres/external-connection-methods" rel="nofollow noreferrer">https://cloud.google.com/sql/docs/postgres/external-connection-methods</a>, there are following options mentioned:</p>

<p><a href="https://i.stack.imgur.com/42xb6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/42xb6.png" alt="enter image description here"></a></p>

<p>We cannot go by Public IP approach since our kubernetes pod IP address will be ever changing. We have already shortlisted Cloud SQL Proxy docker image. So we are left with JDBC Socket Library.</p>

<p>So, comparing Cloud SQL proxy and JDBC Socket Library:</p>

<ul>
<li><a href="https://cloud.google.com/sql/docs/postgres/sql-proxy" rel="nofollow noreferrer">Cloud SQL proxy</a> would be a sidecar container in our kubernetes pod along with our application container. The application container will connect to 'localhost:5432' (proxy) with the cloud sql credentials. The proxy will be given the service account for accessing the cloud sql database. The proxy provides secure connection to cloud sql.</li>
<li><a href="https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory" rel="nofollow noreferrer">JDBC Socket Library</a> also provides secure connection to cloud sql. A Maven dependency needs to added in the application, and the application just has to provide correct database connection string.</li>
</ul>

<p>From the above comparison, JDBC Socket Library seems to be the better way since we won't be needing a sidecar container - cloud sql proxy.</p>

<p>Is there any advantage that the Cloud SQL Proxy would provide as compared to JDBC Socket Library in the case where the application is deployed in Google Kubernetes Engine?</p>

user5155835
<p>There are no advantages of the Cloud SQL proxy over the socket factory, other than the proxy can provide authentication to a wider range of applications, languages, and frameworks. </p>

<p>If your project is already compatible with the Cloud SQL JDBC Socket Factory, you should use it instead. It is more efficient since it can create direct connections for your application. </p>
