Skip to content

Instantly share code, notes, and snippets.

@HenriTEL
Created December 12, 2019 17:46
Show Gist options
  • Save HenriTEL/192e2ec254a8665ed98c93f77c532645 to your computer and use it in GitHub Desktop.
Save HenriTEL/192e2ec254a8665ed98c93f77c532645 to your computer and use it in GitHub Desktop.
kubernetes-client/python setup from a pod using serviceaccount.
from kubernetes import client
SERVICE_ACCOUNT_PATH = '/var/run/secrets/kubernetes.io/serviceaccount'
configuration = client.Configuration()
with open(f'{SERVICE_ACCOUNT_PATH}/token') as token_fd:
configuration.api_key['authorization'] = token_fd.read()
configuration.api_key_prefix['authorization'] = 'Bearer'
configuration.ssl_ca_cert = f'{SERVICE_ACCOUNT_PATH}/ca.crt'
configuration.host = 'https://kubernetes'
k8s = client.CoreV1Api(client.ApiClient(configuration))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment