General
The Odd Couple That Runs the Cloud: Python and Kubernetes Together
Python and Kubernetes form an unlikely but powerful alliance powering cloud platforms at Netflix, Spotify, and beyond. This article explains how Python excels for automation, custom operators, and CI/CD glue despite performance trade-offs.
June 2026 · 6 min read · 2 views · 0 hearts
Advertisement
The Odd Couple That Runs the Cloud
Python is slow. Kubernetes is complicated. Put them together and you've built the engine behind modern cloud platforms. It's not a marriage made in heaven — it's a pragmatic alliance that powers Netflix, Spotify, and most of the infrastructure you rely on daily.
Here's how this unlikely duo actually works.
The Kubernetes Control Plane Speaks Python
When you type kubectl get pods, something interesting happens under the hood. The Kubernetes API server — written in Go — exposes REST endpoints. But the ecosystem around it? That's increasingly Python territory.
kubectl is CLI. Python is the real controller.
The Kubernetes Python client library (kubernetes on PyPI) gives you programmatic access to everything kubectl does, plus things kubectl can't easily handle:
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(f"{pod.metadata.namespace}: {pod.metadata.name}")
That snippet runs in CI/CD pipelines, infrastructure tools, and custom controllers worldwide. The Go runtime underneath is invisible.
Why Python Wins for Automation (Despite the Performance)
Kubernetes isn't latency-sensitive for control plane operations. You're not doing real-time computation — you're orchestrating containers that launch in seconds. A 100ms Python overhead matters less than the 2-second container start time.
The trade-off is clear: Python saves developer hours at the cost of CPU cycles. For cloud platforms operating at scale, that's a deliberate choice.
The Three Patterns You Actually See
-
Custom Operators — Extending Kubernetes behaviour. The popular
kopfframework lets you write operators in 20 lines of Python that watch for custom resources and react. -
Admission Webhooks — Validating or mutating resources before they land in etcd. FastAPI or Flask endpoints that intercept API requests.
-
CI/CD Glue — The scripts that decide which pods to update, rollback, or scale. Python's
kubernetesclient handles the heavy lifting.
The Real Magic: Operators Without a Compiler
Go operators need compilation, Dockerfiles, and registry pushes. Python operators? Write a script, run it locally or inside a pod.
import kopf
import kubernetes
@kopf.on.create('example.dev', 'v1', 'customresources')
def create_fn(body, **kwargs):
# Your logic runs when a CR is created
pass
kopf.run()
That's deployable as a single Python file. Teams iterate faster because there's no compile step. The Kubernetes control plane doesn't care what language talks to it — it speaks REST over HTTP.
Where the Alliance Breaks Down
Event volume. If your operator handles 10,000 events per second, Python's GIL becomes a problem. The solution isn't harder Python — it's better architecture. Buffer events, batch process them, or hand the hot path to Go while keeping the logic in Python.
StatefulSets. Python struggles with the pattern-matching and reconciliation loops that StatefulSets demand. Smart operators use Python for the decision layer and let Kubernetes handle the state.
The Unspoken Truth
Most "cloud-native" infrastructure runs on Go under the hood but Python between the layers. The Kubernetes scheduler, kubelet, and API server are Go. The glue code, monitoring scripts, backup tools, and custom controllers? Python dominates.
Netflix's Titus platform? Python-driven. Spotify's backend infrastructure? Python operators. Even Google's internal tooling leans heavily on Python scripts that talk to Kubernetes.
Practical Advice for Your Next Project
Start with the Python client library. Don't run in-cluster until you need to. Many teams deploy operators as standalone scripts that run on a cron job — simpler than a full deployment.
Use asyncio if you poll frequently. The Kubernetes API rate-limits. Async Python helps you handle multiple resource watches without hitting ceilings.
Log everything. The Python Kubernetes client is verbose when debugging. Set logging.getLogger('kubernetes').setLevel(logging.DEBUG) during development.
The Bottom Line
Python's slowness doesn't matter when the bottleneck is container startup times. Its readability and ecosystem matter a lot when you're debugging a production incident at 3 AM. Kubernetes gives you the orchestration layer. Python gives you the intelligence on top.
They're not competing languages running the same platform. They're complementary tools — and that's exactly how modern cloud platforms stay fast to develop and reliable in production.
Advertisement
Comments
Questions, corrections, and tips stay visible for everyone reading this page.
Join the discussion
No comments yet
Be the first to leave a note — it helps the next reader.