Interview Prep/Python for DevOps/Kubernetes, Docker & SSH clients

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).

All Python for DevOps questions Roadmap: Python for automation

More on Kubernetes, Docker & SSH clients