Rails 5, Google Container Engine and Google Cloud SQL

5/3/2017

I'm trying to connect a Rails app deployed in Google Container Engine to a database hosted in Google Cloud SQL.

I'm following this documentation. According to it, my pods have two containers: spike and cloudsql-proxy.

In this page, we can read the following line:

Provide 127.0.0.1:3306 as the host address your application uses to access the database.

At the very end of the process, I get this:

Return of kubectl logs [pod_name] cloudsql-proxy

2017/05/03 09:50:43 Listening on 127.0.0.1:3306 for [instance_connection_name]
2017/05/03 09:50:43 Ready for new connections

And in kubectl exec -it [pod_name] -- /bin/bash, return of cat log/production.log

ActionView::Template::Error (Unknown MySQL server host '127.0.0.1:3306' (25))

Isn't it fun?

-- Ruff9
google-cloud-sql
google-kubernetes-engine
ruby-on-rails

1 Answer

5/3/2017

I found inspiration in this answer.

Turns out that in database.yml, instead of

production:
 host: 127.0.0.1:3306

it should be

production:
 host: 127.0.0.1
-- Ruff9
Source: StackOverflow