我正在尝试将cloudsql代理部署为sidecar contaier,如下所示:
- name: cloudsql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:1.11
command: ["/cloud_sql_proxy",
"-instances=${CLOUDSQL_INSTANCE}=tcp:5432",
"-credential_file=/secrets/cloudsql/google_application_credentials.json"]
env:
- name: CLOUDSQL_INSTANCE
valueFrom:
secretKeyRef:
name: persistence-cloudsql-instance-creds
key: instance_name
volumeMounts:
- name: my-secrets-volume
mountPath: /secrets/cloudsql
readOnly: true
但是当我部署它时,在日志中出现以下错误:
2019/06/20 13:42:38 couldn't connect to "${CLOUDSQL_INSTANCE}": googleapi: Error 400: Missing parameter: project., required
如何在kubernetes容器中运行的命令中使用环境变量?
最佳答案
如果要在命令中引用环境变量,则需要将它们放在parentheses中,例如:$(CLOUDSQL_INSTANCE)
。