Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use environment variable in kubernetes container command?

I am trying to deploy cloudsql proxy as sidecar contaier like this:

        - 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

But when I deploy this, I get following error in logs:

2019/06/20 13:42:38 couldn't connect to "${CLOUDSQL_INSTANCE}": googleapi: Error 400: Missing parameter: project., required

How could I use environment variable in command that runs inside kubernetes container?

like image 581
Bunyk Avatar asked Dec 29 '25 08:12

Bunyk


1 Answers

If you want to reference environment variables in the command you need to put them in parentheses, something like: $(CLOUDSQL_INSTANCE).

like image 98
Ottovsky Avatar answered Jan 01 '26 21:01

Ottovsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!