Stay organized with collections
Save and categorize content based on your preferences.
Learn how to create a ConfigMap and then configure your Knative serving
services and revisions to use that ConfigMap.
A common use case for a service is to use ConfigMaps to separate application
code from configuration. ConfigMap is similar to
Secret except that you use
a Secret for sensitive information and you use a ConfigMap to store
non-sensitive data such as connection strings, public credentials, hostnames,
and URLs. You can learn more about using ConfigMaps in the
Google Kubernetes Engine documentation.
When you enable containers to access ConfigMaps, you can choose either of these
options:
Mount the ConfigMap as a volume, with ConfigMap entries available as files in
the mounted volume. This is recommended because it ensures that you get the
latest version of the ConfigMap when you are reading it.
There are several ways to create a ConfigMap, as described in the
ConfigMaps page of the
GKE documentation.
For your convenience, the following steps show a simple way to create a
ConfigMap.
When you create a ConfigMap, make sure you create it in the same namespace as
the cluster that is running your Knative serving service. These
instructions use the default namespace.
You can create a ConfigMap from the command line:
kubectlcreateconfigmapNAMEDATA
Replace:
NAME is the name of your ConfigMap object.
DATA can be either:
The --from-file flag and path for each directory that contains
one or more configuration files.
The --from-literal flag and key-value pair for each that you want to
add to the ConfigMap.
The ConfigMap is created and uploaded where it is available to clusters in the
default namespace.
Making a ConfigMap available to a service
After you create a ConfigMap, you can make it available to your
Knative serving service either as a volume or as environment
variables using the Google Cloud console or the Google Cloud CLI
when you deploy a new service or update an
existing service and deploy a revision:
Console
Go to Knative serving in the Google Cloud console:
Click Create Service if you are configuring a
new service you are deploying to. If you are configuring an
existing service, click on the service, then click
Edit & Deploy New Revision.
Under Advanced settings, click Variables and Secrets.
Under Reference a ConfigMap, select the
desired ConfigMap from the pulldown menu.
In the Reference method pulldown menu, select the way you want to use
your ConfigMap, mounted as a volume or exposed as environment variables.
If you are using mount as a volume, specify the path, then click Done.
If you are exposing as environment variables:
Supply the Name of the variable and select the corresponding ConfigMap
value from the Key pulldown menu.
Click Add to add another ConfigMap value.
Supply the Name of the variable and select the corresponding ConfigMap
value from the Key pulldown menu.
Click Done.
Click Next to continue to the next section.
In the Configure how this service is triggered section,
select which connectivity you would like to use to invoke the service.
Click Create to deploy the image to Knative serving and wait
for the deployment to finish.
Command line
You can use the Google Cloud CLI to set ConfigMaps
for new services or to update an existing services:
For existing services, update a ConfigMap by running the
gcloud run services update
command with one of the following parameters:
KEY1=VALUE1,KEY2=VALUE2 with a comma separated
list of name and value pairs for each ConfigMap.
For each KEY you can
specify a mount path, or provide an environment variable. Specify a mount path
by starting with a forward slash /. All other keys correspond to
environment variables. For each VALUE, specify the
ConfigMap name.
How to specify multiple parameters.
Command parameter options
To specify several sets of key-value pairs, you
can specify multiple parameters for readability. Example:
IMAGE_URL with a reference to the container image, for
example, gcr.io/myproject/my-image:latest.
SERVICE with the name of your service.
KEY1=VALUE1,KEY2=VALUE2 with a comma separated
list of name and value pairs for each ConfigMap.
For each KEY you can
specify a mount path, or provide an environment variable. Specify a mount path
by starting with a forward slash /. All other keys correspond to
environment variables. For each VALUE, specify the
ConfigMap name.
How to specify multiple parameters.
Command parameter options
To specify several sets of key-value pairs, you
can specify multiple parameters for readability. Example:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[[["\u003cp\u003eConfigMaps separate application code from configuration data, storing non-sensitive information like connection strings and URLs, as opposed to Secrets which are for sensitive data.\u003c/p\u003e\n"],["\u003cp\u003eConfigMaps can be mounted as volumes, where entries become files, or passed through environment variables, with mounting recommended for ensuring the latest ConfigMap version is used.\u003c/p\u003e\n"],["\u003cp\u003eConfigMaps are created using the \u003ccode\u003ekubectl create configmap\u003c/code\u003e command, specifying the ConfigMap name and data, which can be from files or literals.\u003c/p\u003e\n"],["\u003cp\u003eKnative serving services can utilize ConfigMaps either by mounting them as volumes or by exposing them as environment variables, accessible through the Google Cloud console or CLI.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Cloud CLI can manage ConfigMaps for existing services through the \u003ccode\u003egcloud run services update\u003c/code\u003e command and for new services through the \u003ccode\u003egcloud run deploy\u003c/code\u003e command, using parameters like \u003ccode\u003e--set-config-maps\u003c/code\u003e, \u003ccode\u003e--update-config-maps\u003c/code\u003e, and more.\u003c/p\u003e\n"]]],[],null,["# Using ConfigMaps\n\nLearn how to create a ConfigMap and then configure your Knative serving\nservices and revisions to use that ConfigMap.\n\nA common use case for a service is to use ConfigMaps to separate application\ncode from configuration. ConfigMap is similar to\n[Secret](/anthos/run/archive/docs/configuring/using-secrets) except that you use\na Secret for sensitive information and you use a ConfigMap to store\nnon-sensitive data such as connection strings, public credentials, hostnames,\nand URLs. You can learn more about using ConfigMaps in the\n[Google Kubernetes Engine documentation](/kubernetes-engine/docs/concepts/configmap).\n\nWhen you enable containers to access ConfigMaps, you can choose either of these\noptions:\n\n- Mount the ConfigMap as a volume, with ConfigMap entries available as files in the mounted volume. This is recommended because it ensures that you get the latest version of the ConfigMap when you are reading it.\n- Pass the ConfigMap using [environment variables](/anthos/run/archive/docs/configuring/environment-variables).\n\nCreating a ConfigMap\n--------------------\n\nThere are several ways to create a ConfigMap, as described in the\n[ConfigMaps](/kubernetes-engine/docs/concepts/configmap) page of the\nGKE documentation.\nFor your convenience, the following steps show a simple way to create a\nConfigMap.\n\nWhen you create a ConfigMap, make sure you create it in the same namespace as\nthe cluster that is running your Knative serving service. These\ninstructions use the `default` namespace.\n\nYou can create a ConfigMap from the command line: \n\n kubectl create configmap \u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e \u003cvar translate=\"no\"\u003eDATA\u003c/var\u003e\n\nReplace:\n\n- \u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e is the name of your ConfigMap object.\n- \u003cvar translate=\"no\"\u003eDATA\u003c/var\u003e can be either:\n\n - The `--from-file` flag and path for each directory that contains one or more configuration files.\n - The `--from-literal` flag and key-value pair for each that you want to add to the ConfigMap.\n\nFor example: \n\n kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm\n\nThe ConfigMap is created and uploaded where it is available to clusters in the\n`default` namespace.\n\nMaking a ConfigMap available to a service\n-----------------------------------------\n\nAfter you create a ConfigMap, you can make it available to your\nKnative serving service either as a volume or as environment\nvariables using the Google Cloud console or the Google Cloud CLI\nwhen you deploy a new [service](/anthos/run/archive/docs/deploying#service) or update an\nexisting service and deploy a [revision](/anthos/run/archive/docs/deploying#revision): \n\n### Console\n\n\n1. Go to Knative serving in the Google Cloud console:\n\n [Go to Knative serving](https://console.cloud.google.com/kubernetes/run)\n2. Click **Create Service** if you are configuring a\n new service you are deploying to. If you are configuring an\n existing service, click on the service, then click\n **Edit \\& Deploy New Revision**.\n\n3. Under *Advanced settings* , click **Variables and Secrets**.\n\n4. Under *Reference a ConfigMap*, select the\n desired ConfigMap from the pulldown menu.\n\n - In the *Reference method* pulldown menu, select the way you want to use your ConfigMap, mounted as a volume or exposed as environment variables.\n - If you are using mount as a volume, specify the path, then click **Done**.\n - If you are exposing as environment variables:\n 1. Supply the *Name* of the variable and select the corresponding ConfigMap value from the *Key* pulldown menu.\n 2. Click **Add** to add another ConfigMap value.\n 3. Supply the *Name* of the variable and select the corresponding ConfigMap value from the *Key* pulldown menu.\n 4. Click **Done**.\n\n \u003cbr /\u003e\n\n5. Click **Next** to continue to the next section.\n\n6. In the **Configure how this service is triggered** section,\n select which connectivity you would like to use to invoke the service.\n\n7. Click **Create** to deploy the image to Knative serving and wait\n for the deployment to finish.\n\n### Command line\n\n\nYou can use the Google Cloud CLI to set ConfigMaps\nfor new services or to update an existing services:\n\n\u003cbr /\u003e\n\n- For existing services, update a ConfigMap by running the\n [`gcloud run services update`](/sdk/gcloud/reference/run/services/update)\n command with one of the following parameters:\n\n - [`--set-config-maps`](/sdk/gcloud/reference/run/services/update#--set-config-maps)\n - [`--update-config-maps`](/sdk/gcloud/reference/run/services/update#--update-config-maps)\n - [`--clear-config-maps`](/sdk/gcloud/reference/run/services/update#--clear-config-maps)\n - [`--remove-config-maps`](/sdk/gcloud/reference/run/services/update#--remove-config-maps)\n\n Example: \n\n ```bash\n gcloud run services update SERVICE --update-config-maps KEY1=VALUE1,KEY2=VALUE2\n ```\n\n Replace:\n - \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of your service.\n - \u003cvar translate=\"no\"\u003eKEY1=VALUE1,KEY2=VALUE2\u003c/var\u003e with a comma separated list of name and value pairs for each ConfigMap. For each \u003cvar translate=\"no\"\u003eKEY\u003c/var\u003e you can specify a mount path, or provide an environment variable. Specify a mount path by starting with a forward slash `/`. All other keys correspond to environment variables. For each \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e, specify the ConfigMap name. [How to specify multiple parameters](#command-line). \n\n ### Command parameter options\n\n To specify several sets of key-value pairs, you can specify multiple parameters for readability. Example: \n\n ```bash\n [...]\n --update-config-maps \"KEY=VALUE1\" \\\n --update-config-maps \"KEY=VALUE2\" \\\n --update-config-maps \"KEY=VALUE3\"\n ``` \n OK\n- For new services, set the ConfigMap by running the\n `gcloud run deploy` command with the\n [`--set-config-maps`](/sdk/gcloud/reference/run/deploy#--set-config-maps)\n parameter:\n\n ```bash\n gcloud run deploy SERVICE --image=IMAGE_URL --set-config-maps KEY1=VALUE1,KEY2=VALUE2\n ```\n\n Replace:\n - \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e with a reference to the container image, for example, `gcr.io/myproject/my-image:latest`.\n - \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of your service.\n - \u003cvar translate=\"no\"\u003eKEY1=VALUE1,KEY2=VALUE2\u003c/var\u003e with a comma separated list of name and value pairs for each ConfigMap. For each \u003cvar translate=\"no\"\u003eKEY\u003c/var\u003e you can specify a mount path, or provide an environment variable. Specify a mount path by starting with a forward slash `/`. All other keys correspond to environment variables. For each \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e, specify the ConfigMap name. [How to specify multiple parameters](#command-line). \n\n ### Command parameter options\n\n To specify several sets of key-value pairs, you can specify multiple parameters for readability. Example: \n\n ```bash\n [...]\n --update-config-maps \"KEY=VALUE1\" \\\n --update-config-maps \"KEY=VALUE2\" \\\n --update-config-maps \"KEY=VALUE3\"\n ``` \n OK"]]