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

时间:2019-06-20 13:53:50

标签: kubernetes cloud-sql-proxy

我正尝试将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容器中运行的命令中使用环境变量?

1 个答案:

答案 0 :(得分:1)

如果要在命令中引用环境变量,则需要将其放入parentheses中,例如:$(CLOUDSQL_INSTANCE)