kubectl create configmap: Command Reference for CI/CD
Build a ConfigMap from literals, files, or a whole directory.
kubectl create configmap packages non-secret configuration into a ConfigMap from flags or files. This reference covers the source flags and the pipe-to-apply pattern that keeps configmap creation idempotent in CI.
Common flags and usage
- create configmap <name> --from-literal=k=v: inline key/value
- --from-file=<path>: a file becomes a key (basename) with its content
- --from-file=<dir>: every file in the directory becomes a key
- --from-env-file=<file>: load keys from a dotenv file
- Pipe --dry-run=client -o yaml into apply for idempotency
Example
shell
kubectl create configmap app-cfg \
--from-file=./config/ \
--dry-run=client -o yaml | kubectl apply -f -
kubectl rollout restart deploy/web # pick up the new configIn CI
Like secrets, create configmap is not idempotent, so pipe it through apply on re-runnable jobs. Pods consuming the ConfigMap as env vars do not auto-reload, so follow an update with kubectl rollout restart to roll the new values in.
Key takeaways
- --from-file=<dir> turns each file in a directory into a key.
- create-pipe-apply keeps configmap creation idempotent.
- Env-mounted ConfigMaps need a rollout restart to take effect.
Related guides
kubectl Cheat Sheet: Commands for Everyday KubernetesA kubectl cheat sheet - get, describe, logs, apply, rollout, debug, and context commands for daily Kubernetes…
kubectl create secret: Command Reference for CI/CDReference for kubectl create secret: build generic, docker-registry, and tls Secrets from literals or files,…
kubectl rollout restart: Command Reference for CI/CDReference for kubectl rollout restart: trigger a fresh rolling restart with no spec change, to pick up a rota…
kubectl apply: Command Reference for CI/CDReference for kubectl apply: declarative create-or-update from manifests, server-side apply, dry-run validati…