Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何从Google容器引擎连接Google云SQL?_Ruby On Rails_Google Cloud Sql_Kubernetes_Google Kubernetes Engine - Fatal编程技术网

Ruby on rails 如何从Google容器引擎连接Google云SQL?

Ruby on rails 如何从Google容器引擎连接Google云SQL?,ruby-on-rails,google-cloud-sql,kubernetes,google-kubernetes-engine,Ruby On Rails,Google Cloud Sql,Kubernetes,Google Kubernetes Engine,我正在使用Kubernetes将Rails应用程序部署到Google容器引擎 数据库正在使用谷歌云SQL 我知道数据库的ip地址,并将其设置到我的Kubernetes配置文件中: # web-controller.yml apiVersion: v1 kind: ReplicationController metadata: labels: name: web name: web-controller spec: replicas: 2 selector: nam

我正在使用KubernetesRails应用程序部署到Google容器引擎

数据库正在使用谷歌云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页面中看到负载平衡器入口ip地址


谷歌开发者控制台->存储->SQL中,选择正在运行的数据库并单击链接。从访问控制->授权->授权网络中添加一个新项目并将该IP添加到其中。但是结果是一样的。

从中,似乎“使用0.0.0.0/0 CIDR的SSL连接”是推荐的解决方案。

您需要像Yu Ju Hong所说的那样创建SSL证书,然后您必须告诉ruby在连接类似的东西时使用证书

关于:


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

谢谢。我正在使用数据库url连接远程mysql。所以也许我应该在我的url字符串后面附加它,比如:
mysql2://[my_username]:[my_password]@[database_ip]/myapp?sslca=/path/to/mysql-ssl-ca-cert.pem