# kubectl create configmap: Command Reference for CI/CD

> Reference for kubectl create configmap: build a ConfigMap from literals, files, or a directory, the create-pipe-apply idempotency pattern, and a CI example.

Source: https://latchkey.dev/learn/command-reference/kubectl-create-configmap-command-cli-reference  
Updated: 2026-06-26

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.

## Using this in CI

A runner has no kubeconfig, no cached context, and no interactive auth. Every kubectl invocation in CI needs the context supplied explicitly, and most confusing CI failures here are the command running against the wrong cluster or no cluster at all.

```Terminal
# never rely on the ambient context on a runner
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" get pods

# confirm what you are actually connected to before mutating anything
kubectl config current-context
kubectl cluster-info

# fail fast instead of hanging on an unreachable API server
kubectl --request-timeout=30s get nodes
```

> Always set `--request-timeout` in CI. Without it an unreachable API server hangs until the job times out, which turns a thirty-second failure into a twenty-minute one.

## FAQ

### kubectl create configmap: Command Reference for CI/CD?

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.

### 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
