Kubernetes - update ConfigMap programmatically

0 votes
I have a Kubernetes deployment which uses a ConfigMap with some configuration which is frequently updated. Currently I have to update this configuration manually, by running a script on my local machine that updates the ConfigMap via kubectl.

Is there a way to do this in a more automated fashion?
Sep 3, 2018 in Kubernetes by Hannah
• 18,520 points
4,610 views

1 answer to this question.

0 votes

If you know Python, you can do something like this

from __future__ import print_statement 
import time 
import kubernetes.client from kubernetes.client.rest 
import ApiException from pprint import pprint
# Configure API key authorization: BearerToken 
kubernetes.client.configuration.api_key['authorization'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# kubernetes.client.configuration.api_key_prefix['authorization'] = 'Bearer'
# create an instance of the API class api_instance = 
kubernetes.client.CoreV1Api() 
name = 'name_example' # str | name of the ConfigMap 
namespace = 'namespace_example' # str | object name and auth scope, such as for teams and projects 
body = NULL # object |  
pretty = 'pretty_example' # str | If 'true', then the output is pretty printed. (optional)
try: 
    api_response = api_instance.patch_namespaced_config_map(name, namespace, body, pretty=pretty)
    pprint(api_response) 
except ApiException as e:
    print("Exception when calling CoreV1Api->patch_namespaced_config_map: %s\n" % e)

answered Sep 3, 2018 by Kalgi
• 52,350 points

Related Questions In Kubernetes

+1 vote
4 answers
0 votes
2 answers

How do I update all my pods if the image changed but the tag is the same? - Kubernetes

Make sure your imagePullPolicy is set to Always(this is the ...READ MORE

answered Aug 6, 2019 in Kubernetes by Sirajul
• 59,230 points
3,489 views
0 votes
1 answer

What is ConfigMap in Kubernetes?

Hi@akhtar, A ConfigMap is an API object used ...READ MORE

answered Aug 31, 2020 in Kubernetes by MD
• 95,460 points
931 views
+5 votes
2 answers

Redirecting host to service path in kubernetes

What you are trying to do is ...READ MORE

answered Mar 27, 2018 in Kubernetes by DragonLord999
• 8,450 points
3,578 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
15,477 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,036 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,633 views
0 votes
3 answers

Kubernetes dashboard status-CrashLoopBackOff

I had the same issue, struggled for days. ...READ MORE

answered Apr 24, 2019 in Kubernetes by Bebo
9,078 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