Update k8s ConfigMap or Secret without deleting the existing one
You can get YAML from the kubectl create configmap
command and pipe it to kubectl replace
, like this:
kubectl create configmap foo --from-file foo.properties -o yaml --dry-run | kubectl replace -f -
For future reference, kubectl replace
is now a very handy way to achieve this
kubectl replace -f some_spec.yaml
Let you update a complete configMap (or other objects)
See doc and examples directly here
Copy/pasted from the help:
# Replace a pod using the data in pod.json.kubectl replace -f ./pod.json# Replace a pod based on the JSON passed into stdin.cat pod.json | kubectl replace -f -# Update a single-container pod's image version (tag) to v4kubectl get pod mypod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -# Force replace, delete and then re-create the resourcekubectl replace --force -f ./pod.json
For small changes in configMap
, use edit
kubectl edit configmap <cfg-name>
This will open configMap in vi
editor. Make the changes and save it.