如何在 kubernetes 容器命令中使用环境变量?

How to use environment variable in kubernetes container command?

我正在尝试像这样将 cloudsql 代理部署为 sidecar 容器:

        - 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)