From 317aeeec2279f68daf70d0b7bf8e14ee1859f599 Mon Sep 17 00:00:00 2001 From: Charles Walker Date: Sat, 27 Jan 2018 10:00:44 -0500 Subject: [PATCH 1/3] Add example for remote cluster without kube client on server --- examples/remote_cluster.py | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 examples/remote_cluster.py diff --git a/examples/remote_cluster.py b/examples/remote_cluster.py new file mode 100644 index 0000000000..a73855a198 --- /dev/null +++ b/examples/remote_cluster.py @@ -0,0 +1,58 @@ +# Copyright 2016 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This example demonstrate communication with a remove Kube cluster from a +# server outside of the cluster without kube client installed on it. +# The communication is secured with the use of Bearer token. + +from kubernetes import client, config + + +def main(): + # Define the barer token we are going to use to authenticate. + # See here to create the token: + # https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/ + aToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" + + # Create a configuration object + configuration = client.Configuration() + + # Specify the endpoint of your Kube cluster + configuration.host = "https://XXX.XXX.XXX.XXX:443" + + # Security part. + # In this simple example we are not going to verify the SSL certificate of + # the remote cluster (for simplicity reason) + configuration.verify_ssl = False + # Nevertheless if you want to do it you can with these 2 parameters + # configuration.verify_ssl=True + # ssl_ca_cert is the filepath to the file that contains the certificate. + # configuration.ssl_ca_cert="certificate" + + configuration.api_key = {"authorization": "Bearer " + aToken} + + # Use our configuration + client.Configuration.set_default(configuration) + + # Do calls + v1 = client.CoreV1Api() + print("Listing pods with their IPs:") + ret = v1.list_pod_for_all_namespaces(watch=False) + for i in ret.items: + print("%s\t%s\t%s" % + (i.status.pod_ip, i.metadata.namespace, i.metadata.name)) + + +if __name__ == '__main__': + main() From 8b2b3cd40dbd334e1893a9d0043ee006b4d49871 Mon Sep 17 00:00:00 2001 From: Charles Walker Date: Wed, 25 Jul 2018 23:56:53 +0000 Subject: [PATCH 2/3] Update example for remote cluster without override of default client --- examples/remote_cluster.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/remote_cluster.py b/examples/remote_cluster.py index a73855a198..7f2497941c 100644 --- a/examples/remote_cluster.py +++ b/examples/remote_cluster.py @@ -26,27 +26,27 @@ def main(): aToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # Create a configuration object - configuration = client.Configuration() + aConfiguration = client.Configuration() # Specify the endpoint of your Kube cluster - configuration.host = "https://XXX.XXX.XXX.XXX:443" + aConfiguration.host = "https://XXX.XXX.XXX.XXX:443" # Security part. # In this simple example we are not going to verify the SSL certificate of # the remote cluster (for simplicity reason) - configuration.verify_ssl = False + aConfiguration.verify_ssl = False # Nevertheless if you want to do it you can with these 2 parameters # configuration.verify_ssl=True # ssl_ca_cert is the filepath to the file that contains the certificate. # configuration.ssl_ca_cert="certificate" - configuration.api_key = {"authorization": "Bearer " + aToken} + aConfiguration.api_key = {"authorization": "Bearer " + aToken} - # Use our configuration - client.Configuration.set_default(configuration) + # Create a ApiClient with our config + aApiClient = client.ApiClient(aConfiguration) # Do calls - v1 = client.CoreV1Api() + v1 = client.CoreV1Api(aApiClient) print("Listing pods with their IPs:") ret = v1.list_pod_for_all_namespaces(watch=False) for i in ret.items: From 67ae262a512ff9b738312ec205a6ab291fb15fc5 Mon Sep 17 00:00:00 2001 From: Charles Walker Date: Sat, 27 Oct 2018 09:04:42 -0400 Subject: [PATCH 3/3] fix typo in comment --- examples/remote_cluster.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/remote_cluster.py b/examples/remote_cluster.py index 7f2497941c..8cf39efec5 100644 --- a/examples/remote_cluster.py +++ b/examples/remote_cluster.py @@ -1,4 +1,4 @@ -# Copyright 2016 The Kubernetes Authors. +# Copyright 2018 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This example demonstrate communication with a remove Kube cluster from a +# This example demonstrate communication with a remote Kube cluster from a # server outside of the cluster without kube client installed on it. # The communication is secured with the use of Bearer token.