From 145f4e64c7503647773a6114fbe6bff674155dec Mon Sep 17 00:00:00 2001 From: Jodie Putrino Date: Tue, 16 May 2017 11:00:16 -0600 Subject: [PATCH] Write the Docs: add doc for using configmap data in pods (#3780) * new doc - using configmaps in pods * fix style violation - remove command prompt * Update configure-pod-configmap.md Fixed the endcapture tag --- _data/tasks.yml | 1 + .../configure-pod-container/configmap.md | 30 +- .../configure-pod-configmap.md | 392 ++++++++++++++++++ 3 files changed, 408 insertions(+), 15 deletions(-) create mode 100644 docs/tasks/configure-pod-container/configure-pod-configmap.md diff --git a/_data/tasks.yml b/_data/tasks.yml index ee23a886b6..6f8eab929e 100644 --- a/_data/tasks.yml +++ b/_data/tasks.yml @@ -21,6 +21,7 @@ toc: - docs/tasks/configure-pod-container/configure-pod-initialization.md - docs/tasks/configure-pod-container/attach-handler-lifecycle-event.md - docs/tasks/configure-pod-container/configmap.md + - docs/tasks/configure-pod-container/configure-pod-configmap.md - docs/tools/kompose/user-guide.md - title: Injecting Data Into Applications diff --git a/docs/tasks/configure-pod-container/configmap.md b/docs/tasks/configure-pod-container/configmap.md index 809242231a..de65aed2a8 100644 --- a/docs/tasks/configure-pod-container/configmap.md +++ b/docs/tasks/configure-pod-container/configmap.md @@ -32,7 +32,7 @@ Use the `kubectl create configmap` command to create configmaps from [directorie kubectl create ``` -where is the name you want to assign to the ConfigMap and is the directory, file, or literal value to draw the data from. +where \ is the name you want to assign to the ConfigMap and \ 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 @@ -48,13 +48,13 @@ You can use `kubectl create configmap` to create a ConfigMap from multiple files For example: ```shell -$ kubectl create configmap game-config --from-file=docs/user-guide/configmap/kubectl +kubectl create configmap game-config --from-file=docs/user-guide/configmap/kubectl ``` combines the contents of the `docs/user-guide/configmap/kubectl/` directory ```shell -$ ls docs/user-guide/configmap/kubectl/ +ls docs/user-guide/configmap/kubectl/ game.properties ui.properties ``` @@ -62,7 +62,7 @@ ui.properties into the following ConfigMap: ```shell -$ kubectl describe configmaps game-config +kubectl describe configmaps game-config Name: game-config Namespace: default Labels: @@ -77,7 +77,7 @@ ui.properties: 83 bytes The `game.properties` and `ui.properties` files in the `docs/user-guide/configmap/kubectl/` directory are represented in the `data` section of the ConfigMap. ```shell -$ kubectl get configmaps game-config-2 -o yaml +kubectl get configmaps game-config-2 -o yaml ``` ```yaml @@ -113,13 +113,13 @@ You can use `kubectl create configmap` to create a ConfigMap from an individual 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: ```shell -$ kubectl describe configmaps game-config-2 +kubectl describe configmaps game-config-2 Name: game-config Namespace: default Labels: @@ -133,11 +133,11 @@ 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 -$ kubectl describe configmaps game-config-2 +kubectl describe configmaps game-config-2 Name: game-config Namespace: default Labels: @@ -154,7 +154,7 @@ ui.properties: 83 bytes 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: ```shell -$ kubectl create configmap game-config-3 --from-file== +kubectl create configmap game-config-3 --from-file== ``` where `` is the key you want to use in the ConfigMap and `` is the location of the data source file you want the key to represent. @@ -162,9 +162,9 @@ where `` is the key you want to use in the ConfigMap and ` CONFIG GET maxmemory + 1) "maxmemory" + 2) "2097152" + 127.0.0.1:6379> CONFIG GET maxmemory-policy + 1) "maxmemory-policy" + 2) "allkeys-lru" + ``` + +{% endcapture %} + +{% capture discussion %} + +## Understanding ConfigMaps and Pods + +### Restrictions + +1. You must create a ConfigMap before referencing it in a Pod specification (unless you mark the ConfigMap as "optional"). If you reference a ConfigMaps that doesn't exist, the Pod won't start. Likewise, references to keys that don't exist in the ConfigMap will prevent the pod from starting. + +1. If you use `envFrom` to define environment variables from ConfigMaps, keys that are considered invalid will be skipped. The pod will be allowed to start, but the invalid names will be recorded in the event log (`InvalidVariableNames`). The log message lists each skipped key. For example: + + ```shell + kubectl get events + LASTSEEN FIRSTSEEN COUNT NAME KIND SUBOBJECT TYPE REASON SOURCE MESSAGE + 0s 0s 1 dapi-test-pod Pod Warning InvalidEnvironmentVariableNames {kubelet, 127.0.0.1} Keys [1badkey, 2alsobad] from the EnvFrom configMap default/myconfig were skipped since they are considered invalid environment variable names. + ``` + +1. ConfigMaps reside in a specific [namespace](/docs/user-guide/namespaces/). A ConfigMap can only be referenced by pods residing in the same namespace. + +1. Kubelet doesn't support the use of ConfigMaps for pods not found on the API server. + This includes every pod created using kubectl or indirectly via a replication controller. + It does not include pods created via the Kubelet's `--manifest-url` flag, `--config` flag, or the Kubelet REST API. (Note: these are not commonly-used ways to create pods.) + +{% endcapture %} + +{% capture whatsnext %} +* Learn more about [ConfigMaps](/docs/tasks/configure-pod-container/configmap.html). + +{% endcapture %} + +{% include templates/task.md %}