Skip to content
Latchkey

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 config

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →