Created
December 12, 2019 17:46
-
-
Save HenriTEL/192e2ec254a8665ed98c93f77c532645 to your computer and use it in GitHub Desktop.
kubernetes-client/python setup from a pod using serviceaccount.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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