Kubernetes Python Client

35.0.0 · active · verified Wed Mar 25

Official Python client for the Kubernetes API. Current version: 35.0.0 (Mar 2026). Client major version maps to Kubernetes server minor version (client 35.x ≈ k8s 1.35). Versions jumped from 12.x to 17.x — not a mistake. Two config methods: load_kube_config() for local (~/.kube/config) and load_incluster_config() for pods. Must use stream() module for exec/attach — direct call removed in v4. Still pre-1.0 in practice despite high version numbers.

Warnings

Install

Imports

Quickstart

Kubernetes Python client — list pods and deployments with dual config loading.

# pip install kubernetes
from kubernetes import client, config

# Load config — handles both local and in-pod
try:
    config.load_incluster_config()
except config.ConfigException:
    config.load_kube_config()

# Core API — pods, namespaces, nodes
v1 = client.CoreV1Api()

# List pods in all namespaces
pods = v1.list_pod_for_all_namespaces(watch=False)
for pod in pods.items:
    print(f'{pod.metadata.namespace}/{pod.metadata.name}: {pod.status.phase}')

# Apps API — deployments
apps_v1 = client.AppsV1Api()
deployments = apps_v1.list_deployment_for_all_namespaces()
for d in deployments.items:
    print(f'{d.metadata.name}: {d.spec.replicas} replicas')

# Get specific pod
pod = v1.read_namespaced_pod(name='my-pod', namespace='default')
print(pod.status.pod_ip)

view raw JSON →