Automate Kubernetes With Python

Mike Wolfe
Dev Genius
Published in
6 min readApr 14, 2022

An easy way to get out of running commands manually…

Photo by Possessed Photography on Unsplash

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…

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Written by Mike Wolfe

Software Developer, Tech Enthusiast, Runner. Current project http://sqlcheater.com/ Connect with me on LinkedIn: www.linkedin.com/in/michael-wolfe-176212125

No responses yet

What are your thoughts?