Skip to content

Instantly share code, notes, and snippets.

@jmvrbanac
Last active July 17, 2018 18:07
Show Gist options
  • Save jmvrbanac/2c39fde00e68bad43ddba8ba2e141efd to your computer and use it in GitHub Desktop.
Save jmvrbanac/2c39fde00e68bad43ddba8ba2e141efd to your computer and use it in GitHub Desktop.
Python Kubernetes use dictionary config
from kubernetes.client import ApiClient, Configuration, CoreV1Api
from kubernetes.config import kube_config
def build_k8_client(cfg_dict):
loader = kube_config.KubeConfigLoader(cfg_dict)
config_cls = type.__call__(Configuration)
loader.load_and_set(config_cls)
Configuration.set_default(config_cls)
return ApiClient(configuration=config_cls)
def list_namespaces_names(client):
api = CoreV1Api(client)
response = api.list_namespace()
return [item.metadata.name for item in response.items]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment