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
• 7,340 points
13,631 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,300 points
+1 vote

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

kubectl replace -f file.yaml
answered Apr 24, 2019 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, 2019 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, 2019 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, 2019 in Kubernetes by Sirajul
• 59,230 points
3,679 views
0 votes
1 answer

How to share the files among kubernetes pods without explicti mentioning yaml files?

You can create a shared volume and ...READ MORE

answered Apr 8, 2020 in Kubernetes by Liana
708 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
• 52,360 points
4,069 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
• 7,060 points
7,555 views
+2 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
3,803 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,300 points
2,378 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,300 points
7,933 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP