4

我正在尝试将 cloudsql 代理部署为边车容器,如下所示:

        - 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 容器内运行的命令中使用环境变量?

4

1 回答 1

8

如果要在命令中引用环境变量,则需要将它们放在括号中,例如:$(CLOUDSQL_INSTANCE).

于 2019-06-20T14:29:00.863 回答