Update k8s ConfigMap or Secret without deleting the existing one
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In Kubernetes, you usually update a ConfigMap or Secret in place rather than deleting and recreating it. In-place updates preserve object identity and reduce operational risk during rollout. The important detail is that pods do not always consume new values immediately, so update strategy and restart behavior must be planned together.
In-Place Update With kubectl apply
The most common workflow is editing a manifest and applying it.
For Secrets, use stringData in manifests to avoid manual base64 encoding mistakes.
Kubernetes stores Secret data as base64 in the object, but stringData keeps authoring safer.
Partial Update With kubectl patch
If you need to change one key quickly, patch can be cleaner than full manifest replacement.
Secret patch example:
Use patch carefully in automation. For long-term maintainability, source-controlled manifests are usually preferred.
Make Running Pods Pick Up Changes
How updates propagate depends on how the pod consumes config.
- Environment variables are fixed at pod start and require restart.
- Volume-mounted ConfigMap or Secret files can refresh, but app process may still need reload logic.
A common operational pattern is rollout restart.
This ensures new pod instances read updated values at startup.
Versioned Config Strategy
For high-safety deployments, use versioned config names and update deployment references.
Example approach:
app-config-v12- Update deployment to reference
app-config-v12. - Roll out.
- Remove old config later.
This gives easy rollback by switching reference back to previous version.
Immutable ConfigMaps and Secrets
Kubernetes supports immutable objects for stronger safety.
Immutable objects cannot be updated in place. You must create a new object and update consumers. This is useful when accidental edits are more dangerous than update overhead.
Verify the Update
Always verify both resource and workload behavior.
Application-level verification is still required. Resource update alone does not prove runtime behavior changed as expected.
Security and Audit Notes for Secrets
When handling secrets:
- Avoid printing secret values in logs or terminal history.
- Prefer external secret managers where required by policy.
- Restrict RBAC permissions for secret read and write.
For compliance-sensitive environments, ensure secret rotation procedures and access logs are documented and tested.
Run periodic drill updates in non-production clusters to verify rollout and rollback mechanics still work after platform upgrades.
Common Pitfalls
A common pitfall is updating a ConfigMap and expecting environment variables in running pods to change automatically. Another issue is patching objects manually in production while manifests in Git remain outdated, causing later drift and rollback confusion. Teams also often base64-encode secret strings incorrectly when not using stringData. Failing to restart or reload application processes after updates is another frequent source of false success. Finally, secret updates without strict RBAC and audit discipline can create security incidents even when technical rollout succeeds.
Summary
- Use
kubectl applyorkubectl patchto update ConfigMaps and Secrets in place. - Prefer
stringDatafor safer Secret authoring. - Plan workload refresh behavior based on env-var or volume usage.
- Use rollout restart or versioned config references for controlled rollout.
- Verify both Kubernetes object state and application behavior after each update.

