How to connect Google Cloud SQL from Google Container Engine?

I am using Kubernetes to deploy the Rails application to the Google Container Engine .

The database uses Google Cloud SQL .

I know the IP address of the database and set it to the Kubernetes configuration file:

# web-controller.yml apiVersion: v1 kind: ReplicationController metadata: labels: name: web name: web-controller spec: replicas: 2 selector: name: web template: metadata: labels: name: web spec: containers: - name: web image: gcr.io/my-project-id/myapp:v1 ports: - containerPort: 3000 name: http-server env: - name: RAILS_ENV value: "production" - name: DATABASE_URL value: "mysql2://[my_username]:[my_password]@[database_ip]/myapp" 

Then create:

 $ kubectl create -f web-controller.yml 

From the magazine I saw:

 $ kubectl logs web-controller-038dl Lost connection to MySQL server at 'reading initial communication packet', system error: 0 /usr/local/bundle/gems/mysql2-0.3.20/lib/mysql2/client.rb:70:in `connect' /usr/local/bundle/gems/mysql2-0.3.20/lib/mysql2/client.rb:70:in `initialize' ... 

I see the LoadBalancer Ingress ip address on the Kubernetes UI page in the web services section.

In the Google Developer Console β†’ Storage β†’ SQL, select the executable file and click the link. From Access Controller β†’ Authorization β†’ Authorized networks add a new element and add the IP-address. But the result was the same.

+3
source share
2 answers

You will need to create an SSL certificate, as Yu-Hu Hong said, then you have to tell the ruby ​​to use the certificate when connecting something like

http://makandracards.com/makandra/1701-use-ssl-for-amazon-rds-mysql-and-your-rails-app

Bit about:

sslca: /path/to/mysql-ssl-ca-cert.pem

+2
source

From Unable to access Google Cloud SQL from google container , it seems that "using SSL connection with this 0.0.0.0/0 CIDR" is the recommended solution.

+1
source

All Articles