Kubernetes and Google Cloud SQL

Cloud SQL is a hosted SQL database similar to Amazon RDS for either Mysql or Postgres databases. It supports automated management including backup and deployment.  Since the database is created via the the GCP console it is very easy to create a scalable  and reliable database.

To create a new Database use the GCP Console. If you wish to have failover make sure and enable that option while creating the database.

In order for clients to be able to access the database an ingress rule must be created. Unfortunately GCP only allows the configuration of external IP addresses for ingress into Cloud SQL.  In order to allow your Kubernetes cluster to be able to access the database you would need to assign routable external IPs and add them to the ingress rules for the database.

To get around this issue Cloud SQL Proxy can be used. The Cloud SQL Proxy provides secure access to your Cloud SQL Second Generation instances without having to whitelist IP addresses or setup SSL tunneling.

The steps to setup the Cloud SQL Proxy are fairly straightforward and documented here. 

  1. Create a Service account to connect to the database.
  2. Create a new user to access the database
  3. Create the Secrets for the database
  4. Update the Pod configuration file.

This is one of the few cases where it makes sense to have more than one container within a Pod.  The WordPress client application and the Cloud SQL proxy.

Apply the changes and create a service to expose the app.

Once the service has been created you should be able to access the WordPress blog at


You may also like...