[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-08-30 UTC。"],[],[],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](/kubernetes-engine/enterprise/knative-serving/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](/kubernetes-engine/enterprise/knative-serving/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](/kubernetes-engine/enterprise/knative-serving/docs/deploying#service) or update an\nexisting service and deploy a [revision](/kubernetes-engine/enterprise/knative-serving/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/cloudrun/hello`.\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"]]