Kubernetes python(based on Python 2.7.12) client supports by Alpine in a docker container.
- Kubernetes python client
- Access from Pod demo via
kubernetes.config.load_incluster_config()
To start a container, use the following:
$ docker run -it --name test-kubernetes-python-client \
maiwj/kubernetes-python-client
#!/usr/bin/python# -*- coding: UTF-8 -*-importsysimportosfromkubernetesimportclientfromkubernetes.client.restimportApiExceptiondefmain():
SERVICE_TOKEN_FILENAME="/var/run/secrets/kubernetes.io/serviceaccount/token"SERVICE_CERT_FILENAME="/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"KUBERNETES_HOST="https://%s:%s"% (os.getenv("KUBERNETES_SERVICE_HOST"), os.getenv("KUBERNETES_SERVICE_PORT"))
## configure configuration=client.Configuration()
configuration.host=KUBERNETES_HOSTifnotos.path.isfile(SERVICE_TOKEN_FILENAME):
raiseApiException("Service token file does not exists.")
withopen(SERVICE_TOKEN_FILENAME) asf:
token=f.read()
ifnottoken:
raiseApiException("Token file exists but empty.")
configuration.api_key['authorization'] ="bearer "+token.strip('\n')
ifnotos.path.isfile(SERVICE_CERT_FILENAME):
raiseApiException("Service certification file does not exists.")
withopen(SERVICE_CERT_FILENAME) asf:
ifnotf.read():
raiseApiException("Cert file exists but empty.")
configuration.ssl_ca_cert=SERVICE_CERT_FILENAMEclient.Configuration.set_default(configuration)
try:
ret=client.CoreV1Api().list_namespaced_config_map(namespace=os.getenv("CHART_NAMESPACE"), field_selector=("metadata.name=%s"%os.getenv("CHART_FULLNAME")), watch=False)
printretexceptApiExceptionase:
print("Exception when calling CoreV1Api->list_namespaced_config_map: %s\n"%e)
if__name__=='__main__':
main()- Kuberentes python client is released under the Apache2 License
- This image is released under the MIT License