我有 Google Cloud 项目 A、B、C、D。它们都对 Kubernetes 集群和部署使用类似的设置。项目 A、B 和 C 已于数月前建成。他们都使用 Google Cloud SQL 代理连接到 Google Cloud SQL 服务。现在,当我最近开始为项目 D 设置 Kubernetes 时,我在 Stackdriver 日志记录中看到以下错误:
the default Compute Engine service account is not configured with sufficient permissions to access the Cloud SQL API from this VM. Please create a new VM with Cloud SQL access (scope) enabled under "Identity and API access". Alternatively, create a new "service account key" and specify it using the -credential_file parameter
我比较了 A、B、C 和 D 之间的 Kubernetes 集群之间的差异,但它们似乎是相同的。
这是我正在使用的部署
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: my-site
labels:
system: projectA
spec:
selector:
matchLabels:
system: projectA
template:
metadata:
labels:
system: projectA
spec:
containers:
- name: web
image: gcr.io/customerA/projectA:alpha1
ports:
- containerPort: 80
env:
- name: DB_HOST
value: 127.0.0.1:3306
# These secrets are required to start the pod.
# [START cloudsql_secrets]
- name: DB_USER
valueFrom:
secretKeyRef:
name: cloudsql-db-credentials
key: username
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: cloudsql-db-credentials
key: password
# [END cloudsql_secrets]
# Change <INSTANCE_CONNECTION_NAME> here to include your GCP
# project, the region of your Cloud SQL instance and the name
# of your Cloud SQL instance. The format is
# $PROJECT:$REGION:$INSTANCE
# [START proxy_container]
- name: cloudsql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:1.11
command:
- sh
- -c
- /cloud_sql_proxy -instances=my-gcloud-project:europe-west1:databaseName=tcp:3306
- -credential_file=/secrets/cloudsql/credentials.json
# [START cloudsql_security_context]
securityContext:
runAsUser: 2 # non-root user
allowPrivilegeEscalation: false
# [END cloudsql_security_context]
volumeMounts:
- name: cloudsql-instance-credentials
mountPath: /secrets/cloudsql
readOnly: true
# [END proxy_container]
# [START volumes]
volumes:
- name: cloudsql-instance-credentials
secret:
secretName: cloudsql-instance-credentials
# [END volumes]
所以看起来默认服务帐户没有足够的权限?通过 Google Cloud 控制台创建集群时,Google Cloud 不允许启用 Cloud SQL API。
从我用谷歌搜索这个问题的内容来看,有人说问题出在 gcr.io/cloudsql-docker/gce-proxy 图像上,但我尝试了较新的版本,但仍然出现相同的错误。