<p>I am using <strong>Kubernetes</strong> to deploy a <strong>Rails application</strong> to <strong>Google Container Engine</strong>.</p>

<p>The database is using <strong>Google Cloud SQL</strong>.</p>

<p>I know the database's ip address and set it into my Kubernetes config file:</p>

<pre><code># 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"
</code></pre>

<p>Then create:</p>

<pre><code>$ kubectl create -f web-controller.yml
</code></pre>

<p>From the pod log I saw:</p>

<pre><code>$ 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'
...
</code></pre>

<p>I can see the <strong>LoadBalancer Ingress</strong> ip address from the <strong>Kubernetes UI</strong> page in web service section.</p>

<p>From the <strong>Google Developers Console -> Storage -> SQL</strong>, select the running db and click the link. From <strong>Access Controler -> Authorization -> Authorized Networks</strong>, add a new item and add that IP to there. But the result was the same.</p>

<p>You would need to create the SSL cert like Yu-Ju Hong said, then you would have to tell ruby to use the certificate when connecting something like </p>

<p><a href="http://makandracards.com/makandra/1701-use-ssl-for-amazon-rds-mysql-and-your-rails-app" rel="nofollow">http://makandracards.com/makandra/1701-use-ssl-for-amazon-rds-mysql-and-your-rails-app</a></p>

<p>The bit about:</p>

<p><code>sslca: /path/to/mysql-ssl-ca-cert.pem</code></p>
