Automate Kubernetes With Python
An easy way to get out of running commands manually…
Manually configuring and deploying resources to a Kubernetes cluster can consume a lot of valuable time. In an effort to relieve some of this pain and help automate the process, you could use Helm Charts or even a CI/CD solution. But, believe it or not, you can also use Python! The Python Kubernetes module is a client library that interacts with the Kubernetes REST API to help you manage resources on your cluster. Let’s take a peek at what it can do!
Setup and Installation
The Kubernetes module, by default, is not part of the Python standard library. Therefore, we will need to install it using pip.
pip3 install Kubernetes
The next item we need is obviously, a Kubernetes cluster, I won’t go over how to do that here, but you can check out this article to help you get started with MicroK8s. I recommend using MicroK8s since it can be used on almost any computer (even a Raspberry Pi).
Once you have a cluster running and configured, the last item on the setup list is to obtain a bearer token that will allow us to access the cluster from the Python client.
Disclaimer: When using the token you will get a warning about an unverified HTTPS request. For testing purposes, this can…