Monday, November 11, 2024
No menu items!
HomeCloud ComputingConnecting Google Kubernetes Engine to Cloud SQL using the Auth Proxy Operator

Connecting Google Kubernetes Engine to Cloud SQL using the Auth Proxy Operator

We are constantly looking for ways to simplify the developer experience on Google Cloud.

Google Kubernetes Engine (GKE) is a simple way to automatically deploy, scale, and manage Kubernetes. Cloud SQL is a fully managed relational database service for MySQL, PostgreSQL, and SQL Server. Developers often deploy their applications to GKE and store their data in Cloud SQL, so connecting GKE to Cloud SQL is typically one of the first big steps in deploying a full stack application. The Kubernetes operator simplifies that process.

How to connect from GKE to Cloud SQL

Generally, the easiest way to connect to Cloud SQL is with a language-specific Cloud SQL connector. There are Cloud SQL connectors for Java, Python, and Go — with more to come in the future. If your application is written in one of those languages, we recommend starting with a connector. Otherwise, the Cloud SQL Auth proxy is likely the right choice for your applications running on Google Kubernetes Engine. If you’re willing to join us on the leading edge, the Kubernetes operator is now in Public Preview.

Switching to the Cloud SQL Auth Proxy Kubernetes Operator

The Cloud SQL Proxy Operator is currently in Public Preview. Here are a few exciting benefits for those ready to make the switch:

Configure a Cloud SQL Auth Proxy in 8 lines of YAML — saving you about 40 lines of YAML configuration (or thousands for large clusters)

Simple configuration of a single Cloud SQL Proxy specific resource — allowing multiple Kubernetes applications to share the same proxy

Best practices by default — we maintain the operator and update it to the latest recommendations

Automatic deployment when the proxy configuration changes (coming in the GA release)

Here’s an example of what configuration might look like before the operator. Note how much simpler and more elegant the new operator makes deployment.

code_block[StructValue([(u’code’, u’apiVersion: v1rnkind: Deploymentrnspec:rn template:rn spec:rn containers:rn – name: cloud-sql-proxyrn args: rn – –http-port=9801rn – –http-address=0.0.0.0rn – –health-checkrn – –structured-logsrn – my-project:us-central1:one?unix-socket=/csql/pgrn env:rn – name: DB_SOCKET_PATHrn value: /csql/pgrn image: gcr.io/cloud-sql-connectors/cloud-sql-proxy:2.0.0-preview.2rn imagePullPolicy: IfNotPresentrn livenessProbe:rn failureThreshold: 3rn httpGet:rn path: /livenessrn port: 9801rn scheme: HTTPrn periodSeconds: 30rn successThreshold: 1rn timeoutSeconds: 1rnrnu2193 40 more lines of YAML u2193′), (u’language’, u”), (u’caption’, <wagtail.wagtailcore.rich_text.RichText object at 0x3e5c50608150>)])]

And here is what the configuration looks like for the same project after adding the operator:

code_block[StructValue([(u’code’, u’apiVersion: cloudsql.cloud.google.com/v1alpha1rnkind: AuthProxyWorkloadrnmetadata:rn name: authproxyworkload-samplernspec:rn workloadSelector:rn kind: “Deployment”rn name: “gke-cloud-sql-app”rn instances:rn – connectionString: “my-project:us-central1:one”rn unixSocketPathEnvName: “DB_SOCKET_PATH”rn socketType: “unix”rn unixSocketPath: “/csql/pg”‘), (u’language’, u”), (u’caption’, <wagtail.wagtailcore.rich_text.RichText object at 0x3e5c506089d0>)])]

We want your feedback

While the Cloud SQL Proxy Kubernetes operator is in Public Preview, we want to hear what could make it even better for you. We are working on this project in our public GitHub Repository. You can find the code, quickstart, and contribution guidelines there. We’d love to accept your patches and contributions to this project. We’re hoping with all of the typing we save you on YAML, you might have enough time to create issues or make a pull request. Then someday, we can give your fingers the much-needed vacation they deserve.

Cloud BlogRead More

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments