<p>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 <code>kubectl</code>.</p>

<p>Is there a way to do this in a more automated fashion using the Kubernetes API (from inside or outside Kubernetes)?</p>

<p>There are a couple of Kubernetes clients in many languages if you take a look <a href="https://kubernetes.io/docs/reference/using-api/client-libraries" rel="nofollow noreferrer">here</a>. Python and Go are officially supported. You can automate the steps by calling the client.</p>
<p>If you know Python, you may refer to the <a href="https://github.com/kubernetes-incubator/client-python/blob/master/kubernetes/docs/CoreV1Api.md#patch_namespaced_config_map" rel="nofollow noreferrer">sample</a> below.</p>
<pre><code>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(&quot;Exception when calling CoreV1Api-&gt;patch_namespaced_config_map: %s\n&quot; % e)
</code></pre>
<p>With respect to use APIs internally and externally, you can take a look at the <a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#accessing-the-api-from-a-pod" rel="nofollow noreferrer">wiki</a>. Especially this <a href="https://stackoverflow.com/questions/30690186/how-do-i-access-the-kubernetes-api-from-within-a-pod-container">thread</a> explains how to access APIs from a pod.</p>
<pre><code>KUBE_TOKEN=$(&lt;/var/run/secrets/kubernetes.io/serviceaccount/token)
curl -sSk -H &quot;Authorization: Bearer $KUBE_TOKEN&quot; https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/iot2cloud/configmaps
</code></pre>
