Last active
July 10, 2018 08:57
-
-
Save webwurst/5b3aece21c45a634eb0db6e14b2aa3c5 to your computer and use it in GitHub Desktop.
Kubernetes Python Client
This file contains 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 python:3.4 | |
WORKDIR /usr/src/app | |
COPY . /usr/src/app | |
RUN pip install /usr/src/app | |
# docker build --tag local/kubernetes . | |
# docker run -v $HOME/.kube:/root/.kube -v $PWD:$PWD -w $PWD -ti local/kubernetes python |
This file contains 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
import os | |
from kubernetes import client, config | |
from kubernetes.client import configuration | |
config_file = os.path.join(os.path.expanduser('~'), '.kube', 'config') | |
contexts, active_context = config.list_kube_config_contexts(config_file) | |
config.load_kube_config(config_file, active_context['name']) | |
v1 = client.CoreV1Api() | |
ret = v1.list_pod_for_all_namespaces(watch=False) |
This file contains 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
$ docker run -v $HOME/.kube/config:/root/.kube/config -v $PWD:$PWD -w $PWD -ti local/kubernetes python 19s 211ms | |
Python 3.4.5 (default, Nov 17 2016, 22:34:43) | |
[GCC 4.9.2] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import os | |
>>> | |
>>> from kubernetes import client, config | |
>>> from kubernetes.client import configuration | |
>>> | |
>>> config_file = os.path.join(os.path.expanduser('~'), '.kube', 'config') | |
>>> contexts, active_context = config.list_kube_config_contexts(config_file) | |
>>> | |
>>> config.load_kube_config(config_file, active_context['name']) | |
>>> | |
>>> v1 = client.CoreV1Api() | |
>>> ret = v1.list_pod_for_all_namespaces(watch=False) | |
Traceback (most recent call last): | |
File "/usr/local/lib/python3.4/site-packages/urllib3/util/ssl_.py", line 308, in ssl_wrap_socket | |
context.load_verify_locations(ca_certs, ca_cert_dir) | |
FileNotFoundError: [Errno 2] No such file or directory | |
During handling of the above exception, another exception occurred: | |
Traceback (most recent call last): | |
File "/home/webwurst/Development/github.com/kubernetes-incubator/client-python/kubernetes/client/rest.py", line 196, in request | |
headers=headers) | |
File "/usr/local/lib/python3.4/site-packages/urllib3/request.py", line 66, in request | |
**urlopen_kw) | |
File "/usr/local/lib/python3.4/site-packages/urllib3/request.py", line 87, in request_encode_url | |
return self.urlopen(method, url, **extra_kw) | |
File "/usr/local/lib/python3.4/site-packages/urllib3/poolmanager.py", line 244, in urlopen | |
response = conn.urlopen(method, u.request_uri, **kw) | |
File "/usr/local/lib/python3.4/site-packages/urllib3/connectionpool.py", line 594, in urlopen | |
chunked=chunked) | |
File "/usr/local/lib/python3.4/site-packages/urllib3/connectionpool.py", line 350, in _make_request | |
self._validate_conn(conn) | |
File "/usr/local/lib/python3.4/site-packages/urllib3/connectionpool.py", line 835, in _validate_conn | |
conn.connect() | |
File "/usr/local/lib/python3.4/site-packages/urllib3/connection.py", line 323, in connect | |
ssl_context=context) | |
File "/usr/local/lib/python3.4/site-packages/urllib3/util/ssl_.py", line 310, in ssl_wrap_socket | |
raise SSLError(e) | |
urllib3.exceptions.SSLError: [Errno 2] No such file or directory | |
During handling of the above exception, another exception occurred: | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/home/webwurst/Development/github.com/kubernetes-incubator/client-python/kubernetes/client/apis/core_v1_api.py", line 14377, in list_pod_for_all_namespaces | |
(data) = self.list_pod_for_all_namespaces_with_http_info(**kwargs) | |
File "/home/webwurst/Development/github.com/kubernetes-incubator/client-python/kubernetes/client/apis/core_v1_api.py", line 14475, in list_pod_for_all_namespaces_with_http_info | |
collection_formats=collection_formats) | |
File "/home/webwurst/Development/github.com/kubernetes-incubator/client-python/kubernetes/client/api_client.py", line 326, in call_api | |
_return_http_data_only, collection_formats, _preload_content, _request_timeout) | |
File "/home/webwurst/Development/github.com/kubernetes-incubator/client-python/kubernetes/client/api_client.py", line 150, in __call_api | |
_request_timeout=_request_timeout) | |
File "/home/webwurst/Development/github.com/kubernetes-incubator/client-python/kubernetes/client/api_client.py", line 349, in request | |
headers=headers) | |
File "/home/webwurst/Development/github.com/kubernetes-incubator/client-python/kubernetes/client/rest.py", line 222, in GET | |
query_params=query_params) | |
File "/home/webwurst/Development/github.com/kubernetes-incubator/client-python/kubernetes/client/rest.py", line 199, in request | |
raise ApiException(status=0, reason=msg) | |
kubernetes.client.rest.ApiException: (0) | |
Reason: SSLError | |
[Errno 2] No such file or directory | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment