Creating ConfigMaps

Creating ConfigMaps from Literals, Files and Directories

kubectl 5,150 create configmap fills data from three kinds of source: --from-literal gives one key and value, --from-file makes a key from a file's name (or key=path) with the file's contents as value, and a directory turns every regular file inside into a key. --from-env-file reads KEY=VALUE lines instead:

Filling ConfigMaps from literals, a file and a directoryShell
mkdir -p ~/settings && echo 20 > ~/settings/page-size && echo info > ~/settings/log-level
kubectl create configmap demo-literal --from-literal=LOG_LEVEL=info --from-literal=PAGE_SIZE=20
kubectl create configmap demo-file --from-file=nginx.conf=web/default.conf.template
kubectl create configmap demo-dir --from-file=$HOME/settings/
kubectl get configmap demo-dir -o jsonpath='{.data}'; echo
Output
configmap/demo-literal created
configmap/demo-file created
configmap/demo-dir created
{"log-level":"info\n","page-size":"20\n"}

Values are UTF-8 strings; bytes that are not go into binaryData, base64-encoded. For anything you keep, write the ConfigMap as YAML in Git 1,932 , or generate it with --dry-run=client -o yaml and commit the result.