How does the official Kubernetes Python client authenticate?
BeginnerConceptKubernetes, Docker & SSH clients
Answer
from kubernetes import client, config
try:
config.load_incluster_config() # inside a pod: service account token + CA
except config.ConfigException:
config.load_kube_config() # local: ~/.kube/config, current context
v1 = client.CoreV1Api()
In-cluster it reads /var/run/secrets/kubernetes.io/serviceaccount/ and the KUBERNETES_SERVICE_HOST env var. Locally it honors KUBECONFIG and exec plugins (for EKS, the aws eks get-token exec entry in kubeconfig).
More on Kubernetes, Docker & SSH clients
How do you list pods with high restart counts using the Python client?BeginnerHow do you patch or scale a Deployment with the Python client?IntermediateHow does `watch.Watch()` work, and what is a `410 Gone`?AdvancedHow do you apply a YAML manifest from Python?AdvancedHow do you use the Docker SDK for Python?BeginnerHow do you clean up dangling Docker images and stopped containers with Python?Intermediate