<p>I'm using Kubernetes Python client to manage my local Kubernetes cluster:</p>

<pre><code>from kubernetes import client, config


config = client.Configuration()
config.host = "http://local_master_node:8080"
client.Configuration.set_default(config)
print(client.CoreV1Api().v1.list_node())
</code></pre>

<p>Everything works fine until I need to connect to a project on Google Cloud Kubernetes Engine using the key file provided by customer owning the project from Google like:</p>

<pre><code>{
    "type": "...",
    "project_id": "...",
    "private_key_id": "...",
    "private_key": "...",
    "client_email": "...",
    "client_id": "...",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://accounts.google.com/o/oauth2/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_x509_cert_url": "https://www.googleapis.com/..."
}
</code></pre>

<p>I'm trying to load it (probably doing it in wrong way):</p>

<pre><code>os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = os.path.abspath('credentials.json')
config.load_incluster_config()
</code></pre>

<p>But this code raises an exception  <code>kubernetes.config.config_exception.ConfigException: Service host/port is not set.</code></p>

<p>The questions are:</p>

<ol>
<li><strong>How to provide Google credentials for Kubernetes Python client properly?</strong></li>
<li><strong>If I am on the right track then where can I find the host/port for using with Google Cloud?</strong></li>
</ol>

<p>Some snippets will be appreciated. </p>

Symon
<p>Finally, I myself found the solution.</p>

<p>First, you need to get Kubernetes configuration file. So, go to Google Cloud Platform <code>Kubernetes Engine</code> panel. Select cluster you want to connect and press the <code>connect</code> button. Select <code>Run in Cloud Shell</code> and after you have logged into the shell type suggested string like:</p>

<pre><code>$ gcloud container clusters get-credentials ...
</code></pre>

<p>Then you can find in <code>~/.kube</code> folder the configuration file. Save its content to a yaml-file which you should feed to <code>kubernetes.config.load_kube_config</code> function:</p>

<pre><code>os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = os.path.abspath('credentials.json')
config.load_kube_config(os.path.abspath('config.yaml'))
</code></pre>
