|
|
|
@@ -3,9 +3,6 @@ assignees:
|
|
|
|
|
- eparis
|
|
|
|
|
- pmorie
|
|
|
|
|
title: Configure Containers Using a ConfigMap
|
|
|
|
|
redirect_from:
|
|
|
|
|
- "/docs/user-guide/configmap/index/"
|
|
|
|
|
- "/docs/user-guide/configmap/index.html"
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -24,7 +21,7 @@ This page shows you how to configure an application using a ConfigMap. ConfigMap
|
|
|
|
|
|
|
|
|
|
{% capture steps %}
|
|
|
|
|
|
|
|
|
|
## Use kubectl to create a ConfigMap
|
|
|
|
|
## Use kubectl to create a ConfigMap
|
|
|
|
|
|
|
|
|
|
Use the `kubectl create configmap` command to create configmaps from [directories](#creating-configmaps-from-directories), [files](#creating-configmaps-from-files), or [literal values](#creating-configmaps-from-literal-values):
|
|
|
|
|
|
|
|
|
@@ -33,17 +30,17 @@ kubectl create configmap <map-name> <data-source>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
where \<map-name> is the name you want to assign to the ConfigMap and \<data-source> is the directory, file, or literal value to draw the data from.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The data source corresponds to a key-value pair in the ConfigMap, where
|
|
|
|
|
|
|
|
|
|
* key = the file name or the key you provided on the command line, and
|
|
|
|
|
* key = the file name or the key you provided on the command line, and
|
|
|
|
|
* value = the file contents or the literal value you provided on the command line.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
You can use [`kubectl describe`](/docs/user-guide/kubectl/v1.6/#describe) or [`kubectl get`](/docs/user-guide/kubectl/v1.6/#get) to retrieve information about a ConfigMap. The former shows a summary of the ConfigMap, while the latter returns the full contents of the ConfigMap.
|
|
|
|
|
|
|
|
|
|
### Create ConfigMaps from directories
|
|
|
|
|
|
|
|
|
|
You can use `kubectl create configmap` to create a ConfigMap from multiple files in the same directory.
|
|
|
|
|
You can use `kubectl create configmap` to create a ConfigMap from multiple files in the same directory.
|
|
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
|
@@ -110,10 +107,10 @@ metadata:
|
|
|
|
|
|
|
|
|
|
You can use `kubectl create configmap` to create a ConfigMap from an individual file, or from multiple files.
|
|
|
|
|
|
|
|
|
|
For example,
|
|
|
|
|
For example,
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
kubectl create configmap game-config-2 --from-file=docs/user-guide/configmap/kubectl/game.properties
|
|
|
|
|
kubectl create configmap game-config-2 --from-file=docs/user-guide/configmap/kubectl/game.properties
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
would produce the following ConfigMap:
|
|
|
|
@@ -131,9 +128,9 @@ game.properties: 158 bytes
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
You can pass in the `--from-file` argument multiple times to create a ConfigMap from multiple data sources.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
kubectl create configmap game-config-2 --from-file=docs/user-guide/configmap/kubectl/game.properties --from-file=docs/user-guide/configmap/kubectl/ui.properties
|
|
|
|
|
kubectl create configmap game-config-2 --from-file=docs/user-guide/configmap/kubectl/game.properties --from-file=docs/user-guide/configmap/kubectl/ui.properties
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
@@ -158,8 +155,8 @@ kubectl create configmap game-config-3 --from-file=<my-key-name>=<path-to-file>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
where `<my-key-name>` is the key you want to use in the ConfigMap and `<path-to-file>` is the location of the data source file you want the key to represent.
|
|
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
kubectl create configmap game-config-3 --from-file=game-special-key=docs/user-guide/configmap/kubectl/game.properties
|
|
|
|
@@ -221,12 +218,12 @@ metadata:
|
|
|
|
|
|
|
|
|
|
{% capture discussion %}
|
|
|
|
|
|
|
|
|
|
## Understanding ConfigMaps
|
|
|
|
|
## Understanding ConfigMaps
|
|
|
|
|
|
|
|
|
|
ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable.
|
|
|
|
|
ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable.
|
|
|
|
|
The ConfigMap API resource stores configuration data as key-value pairs. The data can be consumed in pods or provide the configurations for system components such as controllers. ConfigMap is similar to [Secrets](/docs/concepts/configuration/secret/), but provides a means of working with strings that don't contain sensitive information. Users and system components alike can store configuration data in ConfigMap.
|
|
|
|
|
|
|
|
|
|
Note: ConfigMaps should reference properties files, not replace them. Think of the ConfigMap as representing something similar to the a Linux `/etc` directory and its contents. For example, if you create a [Kubernetes Volume](/docs/concepts/storage/volumes/) from a ConfigMap, each data item in the ConfigMap is represented by an individual file in the volume.
|
|
|
|
|
Note: ConfigMaps should reference properties files, not replace them. Think of the ConfigMap as representing something similar to the a Linux `/etc` directory and its contents. For example, if you create a [Kubernetes Volume](/docs/concepts/storage/volumes/) from a ConfigMap, each data item in the ConfigMap is represented by an individual file in the volume.
|
|
|
|
|
|
|
|
|
|
The ConfigMap's `data` field contains the configuration data. As shown in the example below, this can be simple -- like individual properties defined using `--from-literal` -- or complex -- like configuration files or JSON blobs defined using `--from-file`.
|
|
|
|
|
|
|
|
|
|