This page describes how to configure environment variables for your Cloud Run worker pool.
Any configuration change leads to the creation of a new revision. Subsequent revisions will also automatically get this configuration setting unless you make explicit updates to change it.
Required roles
To get the permissions that you need to configure and deploy Cloud Run worker pools, ask your administrator to grant you the following IAM roles:
-
Cloud Run Developer (
roles/run.developer
) on the Cloud Run worker pool -
Service Account User (
roles/iam.serviceAccountUser
) on the service identity
For a list of IAM roles and permissions that are associated with Cloud Run, see Cloud Run IAM roles and Cloud Run IAM permissions. If your Cloud Run worker pool interfaces with Google Cloud APIs, such as Cloud Client Libraries, see the service identity configuration guide. For more information about granting roles, see deployment permissions and manage access.
Set environment variables
You can set environment variables using the Google Cloud CLI when you create a new worker pool or deploy a new revision:
gcloud
To specify environment variables while deploying your worker pool, use the
--set-env-vars
flag:
gcloud beta run worker-pools deploy WORKER_POOL --image IMAGE_URL --set-env-vars KEY1=VALUE1,KEY2=VALUE2
Replace:
- WORKER_POOL: the name of your worker pool
- KEY1=VALUE1,KEY2=VALUE2: the comma-separated list of variable names and values
- IMAGE_URL with a reference to the container image that
contains the worker pool, such as
us-docker.pkg.dev/cloudrun/container/worker-pool:latest
Update environment variables
You can update runtime environment variables for existing services. This is a non-destructive approach that changes or adds runtime environment variables, but doesn't delete them.
gcloud
To update environment variables of an existing worker pool, use the
--update-env-vars
flag:
gcloud beta run worker-pools update WORKER_POOL --update-env-vars KEY1=VALUE1,KEY2=VALUE2
Replace:
- WORKER_POOL: the name of your worker pool
- KEY1=VALUE1,KEY2=VALUE2: the comma-separated list of variable names and values
Delete environment variables
gcloud
To selectively remove environment variables from an existing worker pool, use
the --remove-env-vars
flag:
gcloud beta run worker-pools update WORKER_POOL --remove-env-vars KEY1,KEY2
Replace:
- WORKER_POOL: the name of your worker pool
- KEY1,KEY2: the comma-separated list of variable names
Alternatively, clear all previously set environment variables
with the --clear-env-vars
flag:
gcloud beta run worker-pools update WORKER_POOL --clear-env-vars
Replace WORKER_POOL with the name of your worker pool.
View environment variable configuration for the worker pool
In the Google Cloud console, go to Cloud Run:
Click Worker pools to display the list of deployed worker pools.
Click the worker pool you want to examine to display its details pane.
Click the Containers tab to display worker pool container configuration.
Sample code
For a code sample that shows how to access environment variables in your code, refer to Handling sensitive configuration with Secret Manager in the End user authentication tutorial.
What's next
You can use environment variables to set a buildpacks configuration. For language-specific details, see the buildpacks documentation for: