This commit is contained in:
Rémy Léone 2020-06-16 07:18:55 +02:00
parent 8aa8acf64e
commit 6725d2888d
1 changed files with 116 additions and 115 deletions

View File

@ -8,8 +8,8 @@ card:
--- ---
{{% capture overview %}} {{% capture overview %}}
ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable. Les ConfigMaps vous permettent de découpler les artefacts de configuration du contenu de l'image pour garder les applications conteneurisées portables.
This page provides a series of usage examples demonstrating how to create ConfigMaps and configure Pods using data stored in ConfigMaps. Cette page fournit une série d'exemples d'utilisation montrant comment créer des ConfigMaps et configurer des pods à l'aide des données stockées dans des ConfigMaps.
{{% /capture %}} {{% /capture %}}
@ -21,60 +21,60 @@ This page provides a series of usage examples demonstrating how to create Config
{{% capture steps %}} {{% capture steps %}}
## Create a ConfigMap ## Créer un ConfigMap
You can use either `kubectl create configmap` or a ConfigMap generator in `kustomization.yaml` to create a ConfigMap. Vous pouvez utiliser soit `kubectl create configmap` ou un générateur ConfigMap dans `kustomization.yaml` pour créer un ConfigMap.
Note that `kubectl` starts to support `kustomization.yaml` since 1.14. Notez que `kubectl` prends en charge `kustomization.yaml` à partir de la version 1.14.
### Create a ConfigMap Using kubectl create configmap ### Créer un ConfigMap à l'aide de kubectl create configmap
Use the `kubectl create configmap` command to create configmaps from [directories](#create-configmaps-from-directories), [files](#create-configmaps-from-files), or [literal values](#create-configmaps-from-literal-values): Utilisez la commande `kubectl create configmap` pour créer des Configmaps depuis des [dossiers](#create-configmaps-from-directories), [fichiers](#create-configmaps-from-files), ou des [valeurs littérales](#create-configmaps-from-literal-values):
```shell ```shell
kubectl create configmap <map-name> <data-source> 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. où \<map-name> est le nom que vous souhaitez attribuer à ConfigMap et \<data-source> est le répertoire, le fichier ou la valeur littérale à partir de laquelle récupérer les données.
The data source corresponds to a key-value pair in the ConfigMap, where La source de données correspond à une paire clé-valeur dans ConfigMap, où
* key = the file name or the key you provided on the command line, and * clé = le nom du fichier ou la clé que vous avez fournie sur la ligne de commande, et
* value = the file contents or the literal value you provided on the command line. * valeur = le contenu du fichier ou la valeur littérale que vous avez fournie sur la ligne de commande.
You can use [`kubectl describe`](/docs/reference/generated/kubectl/kubectl-commands/#describe) or [`kubectl get`](/docs/reference/generated/kubectl/kubectl-commands/#get) to retrieve information about a ConfigMap. Vous pouvez utiliser [`kubectl describe`](/docs/reference/generated/kubectl/kubectl-commands/#describe) ou [`kubectl get`](/docs/reference/generated/kubectl/kubectl-commands/#get) pour récupérer des informations sur un ConfigMap.
#### Create ConfigMaps from directories #### Créer des ConfigMaps à partir de répertoires
You can use `kubectl create configmap` to create a ConfigMap from multiple files in the same directory. Vous pouvez utiliser `kubectl create configmap` pour créer un ConfigMap à partir de plusieurs fichiers dans le même répertoire.
For example: Par exemple:
```shell ```shell
# Create the local directory # Créez le répertoire local
mkdir -p configure-pod-container/configmap/ mkdir -p configure-pod-container/configmap/
# Download the sample files into `configure-pod-container/configmap/` directory # Téléchargez les exemples de fichiers dans le répertoire `configure-pod-container/configmap/`
wget https://kubernetes.io/examples/configmap/game.properties -O configure-pod-container/configmap/game.properties wget https://kubernetes.io/examples/configmap/game.properties -O configure-pod-container/configmap/game.properties
wget https://kubernetes.io/examples/configmap/ui.properties -O configure-pod-container/configmap/ui.properties wget https://kubernetes.io/examples/configmap/ui.properties -O configure-pod-container/configmap/ui.properties
# Create the configmap # Créer la configmap
kubectl create configmap game-config --from-file=configure-pod-container/configmap/ kubectl create configmap game-config --from-file=configure-pod-container/configmap/
``` ```
combines the contents of the `configure-pod-container/configmap/` directory combine le contenu du répertoire `configure-pod-container/configmap/`
```shell ```shell
game.properties game.properties
ui.properties ui.properties
``` ```
into the following ConfigMap: dans le ConfigMap suivant:
```shell ```shell
kubectl describe configmaps game-config kubectl describe configmaps game-config
``` ```
where the output is similar to this: où la sortie est similaire à ceci:
```text ```text
Name: game-config Name: game-config
@ -88,13 +88,13 @@ game.properties: 158 bytes
ui.properties: 83 bytes ui.properties: 83 bytes
``` ```
The `game.properties` and `ui.properties` files in the `configure-pod-container/configmap/` directory are represented in the `data` section of the ConfigMap. Les fichiers `game.properties` et `ui.properties` dans le répertoire `configure-pod-container/configmap/` sont représentés dans la section `data` de la ConfigMap.
```shell ```shell
kubectl get configmaps game-config -o yaml kubectl get configmaps game-config -o yaml
``` ```
The output is similar to this: La sortie est similaire à ceci:
```yaml ```yaml
apiVersion: v1 apiVersion: v1
@ -121,23 +121,23 @@ data:
how.nice.to.look=fairlyNice how.nice.to.look=fairlyNice
``` ```
#### Create ConfigMaps from files #### Créer des ConfigMaps à partir de fichiers
You can use `kubectl create configmap` to create a ConfigMap from an individual file, or from multiple files. Vous pouvez utiliser `kubectl create configmap` pour créer un ConfigMap à partir d'un fichier individuel ou de plusieurs fichiers.
For example, Par exemple,
```shell ```shell
kubectl create configmap game-config-2 --from-file=configure-pod-container/configmap/game.properties kubectl create configmap game-config-2 --from-file=configure-pod-container/configmap/game.properties
``` ```
would produce the following ConfigMap: produirait le ConfigMap suivant:
```shell ```shell
kubectl describe configmaps game-config-2 kubectl describe configmaps game-config-2
``` ```
where the output is similar to this: où la sortie est similaire à ceci:
```text ```text
Name: game-config-2 Name: game-config-2
@ -150,19 +150,19 @@ Data
game.properties: 158 bytes game.properties: 158 bytes
``` ```
You can pass in the `--from-file` argument multiple times to create a ConfigMap from multiple data sources. Vous pouvez passer l'argument `--from-file` plusieurs fois pour créer un ConfigMap à partir de plusieurs sources de données.
```shell ```shell
kubectl create configmap game-config-2 --from-file=configure-pod-container/configmap/game.properties --from-file=configure-pod-container/configmap/ui.properties kubectl create configmap game-config-2 --from-file=configure-pod-container/configmap/game.properties --from-file=configure-pod-container/configmap/ui.properties
``` ```
Describe the above `game-config-2` configmap created Décrivez la ConfigMap crée `game-config-2`:
```shell ```shell
kubectl describe configmaps game-config-2 kubectl describe configmaps game-config-2
``` ```
The output is similar to this: La sortie est similaire à ceci:
```text ```text
Name: game-config-2 Name: game-config-2
@ -176,26 +176,26 @@ game.properties: 158 bytes
ui.properties: 83 bytes ui.properties: 83 bytes
``` ```
Use the option `--from-env-file` to create a ConfigMap from an env-file, for example: Utilisez l'option `--from-env-file` pour créer un ConfigMap à partir d'un fichier env, par exemple:
```shell ```shell
# Env-files contain a list of environment variables. # Les fichiers env contiennent une liste de variables d'environnement.
# These syntax rules apply: # Ces règles de syntaxe s'appliquent:
# Each line in an env file has to be in VAR=VAL format. # Chaque ligne d'un fichier env doit être au format VAR=VAL.
# Lines beginning with # (i.e. comments) are ignored. # Les lignes commençant par # (c'est-à-dire les commentaires) sont ignorées.
# Blank lines are ignored. # Les lignes vides sont ignorées.
# There is no special handling of quotation marks (i.e. they will be part of the ConfigMap value)). # Il n'y a pas de traitement spécial des guillemets (c'est-à-dire qu'ils feront partie de la valeur ConfigMap)).
# Download the sample files into `configure-pod-container/configmap/` directory # Téléchargez les exemples de fichiers dans le dossier `configure-pod-container/configmap/`
wget https://kubernetes.io/examples/configmap/game-env-file.properties -O configure-pod-container/configmap/game-env-file.properties wget https://kubernetes.io/examples/configmap/game-env-file.properties -O configure-pod-container/configmap/game-env-file.properties
# The env-file `game-env-file.properties` looks like below # Le fichier env `game-env-file.properties` ressemble à ceci
cat configure-pod-container/configmap/game-env-file.properties cat configure-pod-container/configmap/game-env-file.properties
enemies=aliens enemies=aliens
lives=3 lives=3
allowed="true" allowed="true"
# This comment and the empty line above it are ignored # Ce commentaire et la ligne vide au-dessus sont ignorés
``` ```
```shell ```shell
@ -203,13 +203,13 @@ kubectl create configmap game-config-env-file \
--from-env-file=configure-pod-container/configmap/game-env-file.properties --from-env-file=configure-pod-container/configmap/game-env-file.properties
``` ```
would produce the following ConfigMap: produirait le ConfigMap suivant:
```shell ```shell
kubectl get configmap game-config-env-file -o yaml kubectl get configmap game-config-env-file -o yaml
``` ```
where the output is similar to this: où la sortie est similaire à ceci:
```yaml ```yaml
apiVersion: v1 apiVersion: v1
@ -227,28 +227,28 @@ data:
``` ```
{{< caution >}} {{< caution >}}
When passing `--from-env-file` multiple times to create a ConfigMap from multiple data sources, only the last env-file is used. Lorsque vous passez plusieurs fois `--from-env-file` pour créer un ConfigMap à partir de plusieurs sources de données, seul le dernier fichier env est utilisé.
{{< /caution >}} {{< /caution >}}
The behavior of passing `--from-env-file` multiple times is demonstrated by: Le comportement consistant à passer plusieurs fois `--from-env-file` est démontré par:
```shell ```shell
# Download the sample files into `configure-pod-container/configmap/` directory # Téléchargez les exemples de fichiers dans le répertoire `configure-pod-container/configmap/`
wget https://k8s.io/examples/configmap/ui-env-file.properties -O configure-pod-container/configmap/ui-env-file.properties wget https://k8s.io/examples/configmap/ui-env-file.properties -O configure-pod-container/configmap/ui-env-file.properties
# Create the configmap # Créez le configmap
kubectl create configmap config-multi-env-files \ kubectl create configmap config-multi-env-files \
--from-env-file=configure-pod-container/configmap/game-env-file.properties \ --from-env-file=configure-pod-container/configmap/game-env-file.properties \
--from-env-file=configure-pod-container/configmap/ui-env-file.properties --from-env-file=configure-pod-container/configmap/ui-env-file.properties
``` ```
would produce the following ConfigMap: produirait le ConfigMap suivant:
```shell ```shell
kubectl get configmap config-multi-env-files -o yaml kubectl get configmap config-multi-env-files -o yaml
``` ```
where the output is similar to this: où la sortie est similaire à ceci:
```yaml ```yaml
apiVersion: v1 apiVersion: v1
@ -265,29 +265,29 @@ data:
textmode: "true" textmode: "true"
``` ```
#### Define the key to use when creating a ConfigMap from a file #### Définissez la clé à utiliser lors de la création d'un ConfigMap à partir d'un fichier
You can define a key other than the file name to use in the `data` section of your ConfigMap when using the `--from-file` argument: Vous pouvez définir une clé autre que le nom de fichier à utiliser dans la section `data` de votre ConfigMap lorsque vous utilisez l'argument `--from-file`:
```shell ```shell
kubectl create configmap game-config-3 --from-file=<my-key-name>=<path-to-file> 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. `<my-key-name>` est la clé que vous souhaitez utiliser dans la ConfigMap et `<path-to-file>` est l'emplacement du fichier de source de données que vous souhaitez que la clé représente.
For example: Par exemple:
```shell ```shell
kubectl create configmap game-config-3 --from-file=game-special-key=configure-pod-container/configmap/game.properties kubectl create configmap game-config-3 --from-file=game-special-key=configure-pod-container/configmap/game.properties
``` ```
would produce the following ConfigMap: produirait la ConfigMap suivante:
```shell ```shell
kubectl get configmaps game-config-3 -o yaml kubectl get configmaps game-config-3 -o yaml
``` ```
where the output is similar to this: où la sortie est similaire à ceci:
```yaml ```yaml
apiVersion: v1 apiVersion: v1
@ -309,22 +309,22 @@ data:
secret.code.lives=30 secret.code.lives=30
``` ```
#### Create ConfigMaps from literal values #### Créer des ConfigMaps à partir de valeurs littérales
You can use `kubectl create configmap` with the `--from-literal` argument to define a literal value from the command line: Vous pouvez utiliser `kubectl create configmap` avec l'argument `--from-literal` définir une valeur littérale à partir de la ligne de commande:
```shell ```shell
kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm
``` ```
You can pass in multiple key-value pairs. Vous pouvez transmettre plusieurs paires clé-valeur.
Each pair provided on the command line is represented as a separate entry in the `data` section of the ConfigMap. Chaque paire fournie sur la ligne de commande est représentée comme une entrée distincte dans la section `data` de la ConfigMap.
```shell ```shell
kubectl get configmaps special-config -o yaml kubectl get configmaps special-config -o yaml
``` ```
The output is similar to this: La sortie est similaire à ceci:
```yaml ```yaml
apiVersion: v1 apiVersion: v1
@ -340,15 +340,15 @@ data:
special.type: charm special.type: charm
``` ```
### Create a ConfigMap from generator ### Créer un ConfigMap à partir du générateur
`kubectl` supports `kustomization.yaml` since 1.14. `kubectl` supporte `kustomization.yaml` depuis 1.14.
You can also create a ConfigMap from generators and then apply it to create the object on the Apiserver. Vous pouvez également créer un ConfigMap à partir de générateurs, puis l'appliquer pour créer l'objet sur l'Apiserver.
The generators should be specified in a `kustomization.yaml` inside a directory. Les générateurs doivent être spécifiés dans un `kustomization.yaml` à l'intérieur d'un répertoire.
#### Generate ConfigMaps from files #### Générer des ConfigMaps à partir de fichiers
For example, to generate a ConfigMap from files `configure-pod-container/configmap/game.properties` Par exemple, pour générer un ConfigMap à partir de fichiers `configure-pod-container/configmap/game.properties`
```shell ```shell
# Create a kustomization.yaml file with ConfigMapGenerator # Create a kustomization.yaml file with ConfigMapGenerator
@ -360,14 +360,14 @@ configMapGenerator:
EOF EOF
``` ```
Apply the kustomization directory to create the ConfigMap object. Appliquer le dossier kustomization pour créer l'objet ConfigMap.
```shell ```shell
kubectl apply -k . kubectl apply -k .
configmap/game-config-4-m9dm2f92bt created configmap/game-config-4-m9dm2f92bt created
``` ```
You can check that the ConfigMap was created like this: Vous pouvez vérifier que le ConfigMap a été créé comme ceci:
```text ```text
kubectl get configmap kubectl get configmap
@ -396,17 +396,17 @@ secret.code.lives=30
Events: <none> Events: <none>
``` ```
Note that the generated ConfigMap name has a suffix appended by hashing the contents. Notez que le nom ConfigMap généré a un suffixe obtenu par hachage de son contenu.
This ensures that a new ConfigMap is generated each time the content is modified. Cela garantit qu'un nouveau ConfigMap est généré chaque fois que le contenu est modifié.
#### Define the key to use when generating a ConfigMap from a file #### Définissez la clé à utiliser lors de la génération d'un ConfigMap à partir d'un fichier
You can define a key other than the file name to use in the ConfigMap generator. Vous pouvez définir une clé autre que le nom de fichier à utiliser dans le générateur ConfigMap.
For example, to generate a ConfigMap from files `configure-pod-container/configmap/game.properties` Par exemple, pour générer un ConfigMap à partir du fichier `configure-pod-container/configmap/game.properties`
with the key `game-special-key` avec la clé `game-special-key`
```shell ```shell
# Create a kustomization.yaml file with ConfigMapGenerator # Créer un fichier kustomization.yaml avec ConfigMapGenerator
cat <<EOF >./kustomization.yaml cat <<EOF >./kustomization.yaml
configMapGenerator: configMapGenerator:
- name: game-config-5 - name: game-config-5
@ -415,16 +415,16 @@ configMapGenerator:
EOF EOF
``` ```
Apply the kustomization directory to create the ConfigMap object. Appliquer le dossier kustomization pour créer l'objet ConfigMap.
```text ```text
kubectl apply -k . kubectl apply -k .
configmap/game-config-5-m67dt67794 created configmap/game-config-5-m67dt67794 created
``` ```
#### Generate ConfigMaps from Literals #### Générer des ConfigMaps à partir de littéraux
To generate a ConfigMap from literals `special.type=charm` and `special.how=very`, you can specify the ConfigMap generator in `kustomization.yaml` as Pour générer un ConfigMap à partir de littéraux `special.type=charm` et `special.how=very`, vous pouvez spécifier le générateur ConfigMap dans `kustomization.yaml` comme
```shell ```shell
# Create a kustomization.yaml file with ConfigMapGenerator # Create a kustomization.yaml file with ConfigMapGenerator
@ -437,137 +437,138 @@ configMapGenerator:
EOF EOF
``` ```
Apply the kustomization directory to create the ConfigMap object. Appliquez le dossier kustomization pour créer l'objet ConfigMap.
```text ```text
kubectl apply -k . kubectl apply -k .
configmap/special-config-2-c92b5mmcf2 created configmap/special-config-2-c92b5mmcf2 created
``` ```
## Define container environment variables using ConfigMap data ## Définir des variables d'environnement de conteneur à l'aide des données ConfigMap
### Define a container environment variable with data from a single ConfigMap ### Définissez une variable d'environnement de conteneur avec les données d'une seule ConfigMap
1. Define an environment variable as a key-value pair in a ConfigMap: 1. Définissez une variable d'environnement comme paire clé-valeur dans un ConfigMap:
```shell ```shell
kubectl create configmap special-config --from-literal=special.how=very kubectl create configmap special-config --from-literal=special.how=very
``` ```
1. Assign the `special.how` value defined in the ConfigMap to the `SPECIAL_LEVEL_KEY` environment variable in the Pod specification. 1. Attribuez la valeur `special.how` défini dans ConfigMap à la variable d'environnement `SPECIAL_LEVEL_KEY` dans la spécification du Pod.
{{< codenew file="pods/pod-single-configmap-env-variable.yaml" >}} {{< codenew file="pods/pod-single-configmap-env-variable.yaml" >}}
Create the Pod: Créez le pod:
```shell ```shell
kubectl create -f https://kubernetes.io/examples/pods/pod-single-configmap-env-variable.yaml kubectl create -f https://kubernetes.io/examples/pods/pod-single-configmap-env-variable.yaml
``` ```
Now, the Pod's output includes environment variable `SPECIAL_LEVEL_KEY=very`. Maintenant, la sortie du Pod comprend une variable d'environnement `SPECIAL_LEVEL_KEY=very`.
### Define container environment variables with data from multiple ConfigMaps ### Définir des variables d'environnement de conteneur avec des données de plusieurs ConfigMaps
* As with the previous example, create the ConfigMaps first. * Comme avec l'exemple précédent, créez d'abord les ConfigMaps.
{{< codenew file="configmap/configmaps.yaml" >}} {{< codenew file="configmap/configmaps.yaml" >}}
Create the ConfigMap: Créez le ConfigMap:
```shell ```shell
kubectl create -f https://kubernetes.io/examples/configmap/configmaps.yaml kubectl create -f https://kubernetes.io/examples/configmap/configmaps.yaml
``` ```
* Define the environment variables in the Pod specification. * Définissez les variables d'environnement dans la spécification Pod.
{{< codenew file="pods/pod-multiple-configmap-env-variable.yaml" >}} {{< codenew file="pods/pod-multiple-configmap-env-variable.yaml" >}}
Create the Pod: Créez le pod:
```shell ```shell
kubectl create -f https://kubernetes.io/examples/pods/pod-multiple-configmap-env-variable.yaml kubectl create -f https://kubernetes.io/examples/pods/pod-multiple-configmap-env-variable.yaml
``` ```
Now, the Pod's output includes environment variables `SPECIAL_LEVEL_KEY=very` and `LOG_LEVEL=INFO`. Maintenant, la sortie du Pod comprend des variables d'environnement `SPECIAL_LEVEL_KEY=very` et `LOG_LEVEL=INFO`.
## Configure all key-value pairs in a ConfigMap as container environment variables ## Configurer toutes les paires clé-valeur dans un ConfigMap en tant que variables d'environnement de conteneur
{{< note >}} {{< note >}}
This functionality is available in Kubernetes v1.6 and later. Cette fonctionnalité est disponible dans Kubernetes v1.6 et versions ultérieures.
{{< /note >}} {{< /note >}}
* Create a ConfigMap containing multiple key-value pairs. * Créez un ConfigMap contenant plusieurs paires clé-valeur.
{{< codenew file="configmap/configmap-multikeys.yaml" >}} {{< codenew file="configmap/configmap-multikeys.yaml" >}}
Create the ConfigMap: Créez le ConfigMap:
```shell ```shell
kubectl create -f https://kubernetes.io/examples/configmap/configmap-multikeys.yaml kubectl create -f https://kubernetes.io/examples/configmap/configmap-multikeys.yaml
``` ```
* Use `envFrom` to define all of the ConfigMap's data as container environment variables. * Utilisez `envFrom` pour définir toutes les données du ConfigMap en tant que variables d'environnement du conteneur.
The key from the ConfigMap becomes the environment variable name in the Pod. La clé de ConfigMap devient le nom de la variable d'environnement dans le pod.
{{< codenew file="pods/pod-configmap-envFrom.yaml" >}} {{< codenew file="pods/pod-configmap-envFrom.yaml" >}}
Create the Pod: Créez le pod:
```shell ```shell
kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-envFrom.yaml kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-envFrom.yaml
``` ```
Now, the Pod's output includes environment variables `SPECIAL_LEVEL=very` and `SPECIAL_TYPE=charm`. Maintenant, la sortie du Pod comprend les variables d'environnement `SPECIAL_LEVEL=very` et `SPECIAL_TYPE=charm`.
## Use ConfigMap-defined environment variables in Pod commands ## Utiliser des variables d'environnement définies par ConfigMap dans les commandes du Pod
You can use ConfigMap-defined environment variables in the `command` section of the Pod specification using the `$(VAR_NAME)` Kubernetes substitution syntax. Vous pouvez utiliser des variables d'environnement définies par ConfigMap dans la section `command` de la spécification du Pod en utilisant la syntaxe de substitution Kubernetes `$(VAR_NAME)`.
For example, the following Pod specification Par exemple, la spécification de pod suivante
{{< codenew file="pods/pod-configmap-env-var-valueFrom.yaml" >}} {{< codenew file="pods/pod-configmap-env-var-valueFrom.yaml" >}}
created by running créé en exécutant
```shell ```shell
kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-env-var-valueFrom.yaml kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-env-var-valueFrom.yaml
``` ```
produces the following output in the `test-container` container: produit la sortie suivante dans le conteneur `test-container`:
```shell ```shell
very charm very charm
``` ```
## Add ConfigMap data to a Volume ## Ajouter des données ConfigMap à un volume
As explained in [Create ConfigMaps from files](#create-configmaps-from-files), when you create a ConfigMap using ``--from-file``, the filename becomes a key stored in the `data` section of the ConfigMap. The file contents become the key's value. Comme expliqué dans [Créer des ConfigMaps à partir de fichiers](#create-configmaps-from-files), lorsque vous créez un ConfigMap à l'aide `--from-file`, le nom de fichier devient une clé stockée dans la section `data` du ConfigMap.
Le contenu du fichier devient la valeur de la clé.
The examples in this section refer to a ConfigMap named special-config, shown below. Les exemples de cette section se réfèrent à un ConfigMap nommé special-config, illustré ci-dessous.
{{< codenew file="configmap/configmap-multikeys.yaml" >}} {{< codenew file="configmap/configmap-multikeys.yaml" >}}
Create the ConfigMap: Créez le ConfigMap:
```shell ```shell
kubectl create -f https://kubernetes.io/examples/configmap/configmap-multikeys.yaml kubectl create -f https://kubernetes.io/examples/configmap/configmap-multikeys.yaml
``` ```
### Populate a Volume with data stored in a ConfigMap ### Remplissez un volume avec des données stockées dans un ConfigMap
Add the ConfigMap name under the `volumes` section of the Pod specification. Ajoutez le nom ConfigMap sous la section `volumes` de la spécification Pod.
This adds the ConfigMap data to the directory specified as `volumeMounts.mountPath` (in this case, `/etc/config`). Ceci ajoute les données ConfigMap au répertoire spécifié comme `volumeMounts.mountPath` (dans ce cas, `/etc/config`).
The `command` section lists directory files with names that match the keys in ConfigMap. La section `command` répertorie les fichiers de répertoire dont les noms correspondent aux clés de ConfigMap.
{{< codenew file="pods/pod-configmap-volume.yaml" >}} {{< codenew file="pods/pod-configmap-volume.yaml" >}}
Create the Pod: Créez le pod:
```shell ```shell
kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-volume.yaml kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-volume.yaml
``` ```
When the pod runs, the command `ls /etc/config/` produces the output below: Lorsque le pod s'exécute, la commande `ls /etc/config/` produit la sortie ci-dessous:
```shell ```shell
SPECIAL_LEVEL SPECIAL_LEVEL
@ -575,7 +576,7 @@ SPECIAL_TYPE
``` ```
{{< caution >}} {{< caution >}}
If there are some files in the `/etc/config/` directory, they will be deleted. S'il y a des fichiers dans le dossier `/etc/config/`, ils seront supprimés.
{{< /caution >}} {{< /caution >}}
### Add ConfigMap data to a specific path in the Volume ### Add ConfigMap data to a specific path in the Volume