Kubernetes GKE吊舱未连接到Cloudsql
我的应用程序似乎无法连接到代理,因此无法连接我的Cloudsql数据库 以下是我的设置: my-simple-app.yamlKubernetes GKE吊舱未连接到Cloudsql,kubernetes,google-cloud-platform,google-cloud-sql,google-kubernetes-engine,cloud-sql-proxy,Kubernetes,Google Cloud Platform,Google Cloud Sql,Google Kubernetes Engine,Cloud Sql Proxy,我的应用程序似乎无法连接到代理,因此无法连接我的Cloudsql数据库 以下是我的设置: my-simple-app.yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: labels: name: web name: web spec: replicas: 2 selector: matchLabels: name: web strategy: type: Rolli
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
name: web
name: web
spec:
replicas: 2
selector:
matchLabels:
name: web
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
template:
metadata:
labels:
name: web
spec:
nodeSelector:
cloud.google.com/gke-nodepool: default-pool
containers:
- image: joelaw/nameko-hello:0.2
name: web
env:
- name: DB_HOST
value: 127.0.0.1
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: cloudsql-db-credentials
key: password
- name: DB_USER
valueFrom:
secretKeyRef:
name: cloudsql-db-credentials
key: username
ports:
- containerPort: 3000
name: http-server
- image: gcr.io/cloudsql-docker/gce-proxy:1.09
name: cloudsql-proxy
command: ["/cloud_sql_proxy", "--dir=/cloudsql",
"-instances=spheric-veric-task:asia-southeast1:authdb:5432",
"-credential_file=/secrets/cloudsql/credentials.json"]
volumeMounts:
- name: cloudsql-instance-credentials
mountPath: /secrets/cloudsql
readOnly: true
- name: ssl-certs
mountPath: /etc/ssl/certs
- name: cloudsql
mountPath: /cloudsql
volumes:
- name: cloudsql-instance-credentials
secret:
secretName: cloudsql-instance-credentials
- name: ssl-certs
hostPath:
path: /etc/ssl/certs
- name: cloudsql
emptyDir:
我想我已经正确地设置了秘密
下面是我从实例中收集的一些数据:
豆荚快乐地生活着:
web-69c7777c68-s2jt6 2/2 Running 0 9m
web-69c7777c68-zbwtv 2/2 Running 0 9m
运行时:kubectl记录web-69c77c68-zbwtv-c cloudsql代理
它记录了这一点:
2019/04/04 03:25:35 using credential file for authentication; email=auth-db-user@spheric-verve-228610.iam.gserviceaccount.com
2019/04/04 03:25:35 Listening on /cloudsql/spheric-veric-task:asia-southeast1:authdb:5432/.s.PGSQL.5432 for spheric-veric-task:asia-southeast1:authdb:5432
2019/04/04 03:25:35 Ready for new connections
由于应用程序未配置为连接到db,因此我所做的是通过以下方式将ssh连接到pod中:
kubectl exec -it web-69c7777c68-mrdpn -- /bin/bash
# Followed by installing postgresql driver:
apt-get install postgresql
# Trying to connect to cloudsql:
psql -h 127.0.0.1 -p 5432 -U
在容器中运行psql时:
psql: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
有谁能告诉我应该怎么做才能连接到DB吗?您指定的实例连接字符串错误,因此代理正在侦听/cloudsql/目录中的unix套接字,而不是TCP端口 要让代理侦听TCP端口,请使用以下命令:
-instances=<INSTANCE_CONNECTION_NAME>=tcp:5432
在kubectl exec命令中,我看不到您指定pod中要连接的容器。您确定要连接到SQL代理容器吗?它是否自己链接到它?或者我必须创建一个服务来链接它们@科尔班。感谢您的回复也许我创建了一个代理实例,但没有连接两个容器?我相信您是正确的,非常了解。。。这里有一个指向cloudsql代理的GitHub页面的链接,该页面列出了示例和命令行选项。感谢mate,设法改善这种情况,现在当我检查代理的日志时,我得到了以下信息:2019/04/05 01:34:00使用凭证文件进行身份验证;email=auth db-2019/04/05 01:34:00收听127.0.0.1:5432获取全球veric任务:亚洲东南部1:authdb 2019/04/05 01:34:00准备好新连接。但是当我尝试在我的应用程序容器中使用psql时,我仍然收到相同的错误:psql:无法连接到服务器:没有这样的文件或目录是在本地运行并接受Unix域套接字上连接的服务器/var/run/postgresql/.s.PGSQL.5433?@Joe.L-确保告诉postgres您希望它连接到127.0.0.1的位置-psql-U postgres-h 127.0.0.1I我尝试过psql主机已声明,但仍返回相同的错误代码。不确定这里发生了什么如果是相同的错误,psql没有遵循这些标志。也许您还需要指定端口?psql-P5432-H127.0.0.1
-instances=<INSTANCE_CONNECTION_NAME>