I can login to a pod using
kubectl exec <pod-name> -- <command>
as explained in this answer.
But I want to achieve this using a python script, and then I wish to use the same python script to edit the yaml file inside that pod.
How can I do this? I'm new to both python and kubernetes so please help me get started.
CodePudding user response:
Take a look at the official Kubernetes client for Python https://github.com/kubernetes-client/python/
CodePudding user response:
As a starting point, look into Kubernetes client libraries - since you're using python, that one: https://github.com/kubernetes-client/python . Keeping in mind exec/attach support is problematic.
Copying files into a container, you have the following thread on SO: Copy file from pod to host by using kubernetes python client . I'm not sure in-container direct edition would be easy / better pull your existing configuration if needed, then overwrite it.
Also consider using a ConfigMap, configuring your workload. Then, you could either trigger a restart of your Pods, when that configuration is changed, or look into something better ... Prometheus ships with the prometheus config reloader: a sidecar, that would watch for changes to some ConfigMaps, installs the last copy on a volume that would be shared with your main application, then send some signal instructing that application to re-read its configuration...