Updating kubernetes configmap/secret without removing the existing one

+1 vote

I'm using Kubernetes secret and configmap to manage our properties. I am using a design that keeps the property piles in a git repository and am using build server Toughtworks GO to automatically deploy it to my configmaps and secrets to my kubernetes cluster.

Right now, I've to delete the current configmap and secret to add the new ones to update:

step1: kubectl delete configmap foo

step2: kubectl create configmap foo --from-file foo.properties

Is there any other way to do this rather than deleting the old one to add new. Because it may damage the containers currently using the old configmaps if the new one hasn't been created yet.

Jul 16, 2018 in Kubernetes by shubham
• 6,890 points
2,581 views

4 answers to this question.

+1 vote

You can fetch the YAML from kubectl, create configmaps command and the pipe the result to substitute kubectl:

kubectl create configmap foo --from-file foo.properties -o yaml --dry-run | kubectl replace -f -
answered Jul 16, 2018 by ajs3033
• 7,280 points
+1 vote

The following command lets you update a complete configMap or even other objects.

kubectl replace -f file.yaml
answered Apr 24 by Nayak
+1 vote

You can use something like this:

# 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 v4
kubectl get pod mypod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -

# Force replace, delete and then re-create the resource
kubectl replace --force -f ./pod.json
answered Apr 24 by Rahul
+1 vote

You can use edit for small changes in configMap in the following way:

kubectl edit configmap <cfg-name>
answered Apr 24 by Vinayak

Related Questions In Kubernetes

0 votes
1 answer

What is the difference between config map and secret in kubernetes?

Config maps ideally stores application configuration in ...READ MORE

answered Jul 17 in Kubernetes by Sirajul
• 16,640 points
43 views
0 votes
1 answer

Error saying "The specified bucket does not exist" in kubernetes

Bucket is created in another region. Looks like ...READ MORE

answered Aug 31, 2018 in Kubernetes by Kalgi
• 39,150 points
232 views
0 votes
2 answers

Restart pods when configmap updates in Kubernetes?

Use Deployments, and consider your ConfigMaps to ...READ MORE

answered Aug 31, 2018 in Kubernetes by Nilesh
• 6,900 points
3,065 views
0 votes
1 answer

Kubernetes - update ConfigMap programmatically

If you know Python, you can do ...READ MORE

answered Sep 3, 2018 in Kubernetes by Kalgi
• 39,150 points
465 views
0 votes
1 answer
+5 votes
7 answers

Docker swarm vs kubernetes

Swarm is easy handling while kn8 is ...READ MORE

answered Aug 27, 2018 in Docker by Mahesh Ajmeria
977 views
0 votes
1 answer

Modifying a deployment without editing the file manually

You can try kubectl patch to do ...READ MORE

answered Aug 24, 2018 in Kubernetes by ajs3033
• 7,280 points
42 views
0 votes
1 answer

Increasing the shm size of a kubernetes container

You cannot achieve this in kubernetes pod. ...READ MORE

answered Sep 12, 2018 in Kubernetes by ajs3033
• 7,280 points
640 views