DevOps & Cloud

kubernetes

The steering wheel for Kubernetes clusters — command an army of containers from Python instead of a terminal.

Install it: pip install kubernetes

What does it do?

Kubernetes manages fleets of containers across many machines, deciding what runs where, restarting things that crash, and scaling up when traffic spikes, like an air traffic controller for software instead of planes. This library lets Python code talk to that control system directly: list what’s running, deploy something new, scale an app from three copies to three hundred. It mirrors the same commands you’d normally type into the kubectl tool, just callable from code instead of a keyboard.

See it in action

This connects to a Kubernetes cluster and lists every running pod (a group of containers) along with which section of the cluster it lives in.

from kubernetes import client, config

config.load_kube_config()
v1 = client.CoreV1Api()

pods = v1.list_pod_for_all_namespaces(watch=False)
for pod in pods.items:
    print(pod.metadata.namespace, pod.metadata.name)

Why would a non-developer care?

Nearly every large website you use, from social media to streaming to shopping, runs on infrastructure managed by something like Kubernetes, because it’s what lets services survive a server crashing at 3 a.m. without anyone waking up. This library is how companies build their own automation on top of that system rather than clicking through it by hand.

Real-world examples

Kubernetes was born inside Google, based on internal systems it used to run search and Gmail at massive scale, and was open-sourced in 2014. Platform teams at large tech companies write Python automation using this exact client to manage deployments across clusters. Without a library like this, tracking thousands of moving containers would require someone manually running commands one at a time — an impossible task at real-world scale.

Who uses it

Platform and infrastructure engineers building automation, dashboards, or custom tools on top of a Kubernetes cluster.

How it compares to alternatives

Where the docker library talks to a single machine’s containers, this one talks to an entire orchestrated cluster — a different scale of problem. Ansible can also manage Kubernetes resources at a higher, more declarative level, but this library is for teams who need fine-grained, code-level control.

Fun fact

Kubernetes comes from the Greek word for helmsman, the person who steers a ship, which is also where the word governor originates.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries