我在 GCP 中有两个项目,即。project1
和project2
我mysql
在 project1 中有设置实例。
我还在mypod cloudsqlproxy中设置cloudsqlproxy
(pod)和mypod
GKE 集群。project2.
I want to access mysql instance from
through
我有以下代码cloudmysqlproxy
apiVersion: v1
kind: Service
metadata:
name: cloudsqlproxy-service-mainnet
namespace: dev
spec:
ports:
- port: 3306
targetPort: port-mainnet
selector:
app: cloudsqlproxy
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: cloudsqlproxy
namespace: dev
spec:
replicas: 1
selector:
matchLabels:
app: cloudsqlproxy
template:
metadata:
labels:
app: cloudsqlproxy
spec:
containers:
# Make sure to specify image tag in production
# Check out the newest version in release page
# https://github.com/GoogleCloudPlatform/cloudsql-proxy/releases
- name: cloudsqlproxy
image: b.gcr.io/cloudsql-docker/gce-proxy:latest
# 'Always' if imageTag is 'latest', else set to 'IfNotPresent'
imagePullPolicy: Always
name: cloudsqlproxy
command:
- /cloud_sql_proxy
- -dir=/cloudsql
- -instances=project1:asia-east1:development=tcp:0.0.0.0:3306
- -credential_file=/credentials/credentials.json
ports:
- name: port-mainnet
containerPort: 3306
volumeMounts:
- mountPath: /cloudsql
name: cloudsql
- mountPath: /credentials
name: cloud-sql-client-account-token
volumes:
- name: cloudsql
emptyDir:
- name: cloud-sql-client-account-token
secret:
secretName: cloud-sql-client-account-token
我已cloud-sql-client-account-token
按以下方式设置:
kubectl create secret cloud-sql-client-account-token --from-file=credentials.json=$HOME/credentials.json
我credentials.json
从project1
.
当我尝试从我的 pod 访问 mysql 实例时,出现以下错误:
mysql --host=cloudsqlproxy-service-mainnet.dev.svc.cluster.local --port=3306
ERROR 1045 (28000): Access denied for user 'root'@'cloudsqlproxy~35.187.201.86' (using password: NO)
和cloud-proxy
日志,我得到以下信息:
2018/11/25 00:35:31 Instance project1:asia-east1:development closed connection
是否需要在与project2
pod 相同的项目 ( ) 中启动 mysql 实例?我错过了什么?
编辑
我可以通过这样的设置访问本地机器上的代理
/cloud_sql_proxy -instances=project1:asia-east1:development=tcp:3306
然后使用 mysql 客户端连接到代理。