问题描述
我正在使用 Kubernetes 将 Rails应用程序部署到 Google Container Engine .
数据库正在使用 Google Cloud SQL .
我知道数据库的IP地址并将其设置到我的Kubernetes配置文件中:
# 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"
然后创建:
$ kubectl create -f web-controller.yml
从广告连播日志中,我看到了:
$ 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'
...
我可以在Web服务部分的 Kubernetes UI 页面中看到 LoadBalancer Ingress IP地址.
在 Google Developers Console->存储-> SQL 中,选择正在运行的数据库,然后单击链接.在访问控制->授权->授权网络中,添加一个新项目并将该IP添加到那里.但是结果是一样的.
您需要像Yu-Ju Hong所说的那样创建SSL证书,然后在连接
http://makandracards.com/makandra/1701-use-ssl-for-amazon-rds-mysql-and-your-rails-app
有关:
sslca: /path/to/mysql-ssl-ca-cert.pem
I am using Kubernetes to deploy a Rails application to Google Container Engine.
The database is using Google Cloud SQL.
I know the database's ip address and set it into my Kubernetes config 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 pod log 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 can see the LoadBalancer Ingress ip address from the Kubernetes UI page in web service section.
From the Google Developers Console -> Storage -> SQL, select the running db and click the link. From Access Controler -> Authorization -> Authorized Networks, add a new item and add that IP to there. But the result was the same.
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
http://makandracards.com/makandra/1701-use-ssl-for-amazon-rds-mysql-and-your-rails-app
The bit about:
sslca: /path/to/mysql-ssl-ca-cert.pem
这篇关于如何从Google Container Engine连接Google Cloud SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!