<p>So I have just started using Kubernetes API server and I tried this example :</p>

<pre><code>from kubernetes import client, config
def main():
    # Configs can be set in Configuration class directly or using helper
    # utility. If no argument provided, the config will be loaded from
    # default location.
    config.load_kube_config()

    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()
</code></pre>

<p>This worked but it returned the pods that are on my local minikube, I want to get the pods that are at the kubernetes server here :
<code>http://192.168.237.115:8080</code>
How do I do that?</p>

<p>When I do <code>kubectl config view</code> , I get this :</p>

<pre><code>apiVersion: v1
clusters:
- cluster:
    certificate-authority: /home/piyush/.minikube/ca.crt
    server: https://192.168.99.100:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /home/piyush/.minikube/apiserver.crt
    client-key: /home/piyush/.minikube/apiserver.key
</code></pre>

<p>I know this is for the local cluster I set up. I want to know how to modify this to make api requests to kubernetes server  on <code>http://192.168.237.115:8080</code> </p>

<p>You can actually create a simple api wrapper. This way you can pass through different yaml configuration files, that I imagine may have different hosts</p>

<pre><code>import yaml

from kubernetes import client
from kubernetes.client import Configuration
from kubernetes.config import kube_config


class K8s(object):
    def __init__(self, configuration_yaml):
        self.configuration_yaml = configuration_yaml
        self._configuration_yaml = None

    @property
    def config(self):
        with open(self.configuration_yaml, 'r') as f:
            if self._configuration_yaml is None:
                self._configuration_yaml = yaml.load(f)
        return self._configuration_yaml

    @property
    def client(self):
        k8_loader = kube_config.KubeConfigLoader(self.config)
        call_config = type.__call__(Configuration)
        k8_loader.load_and_set(call_config)
        Configuration.set_default(call_config)
        return client.CoreV1Api()


# Instantiate your kubernetes class and pass in config
kube_one = K8s(configuration_yaml='~/.kube/config1')
kube_one.client.list_pod_for_all_namespaces(watch=False)

kube_two = K8s(configuration_yaml='~/.kube/config2')
kube_two.client.list_pod_for_all_namespaces(watch=False)
</code></pre>

<p>Also another neat reference in libcloud. <a href="https://github.com/apache/libcloud/blob/trunk/libcloud/container/drivers/kubernetes.py" rel="noreferrer">https://github.com/apache/libcloud/blob/trunk/libcloud/container/drivers/kubernetes.py</a>. </p>

<p>Good luck! Hope this helps! :) </p>
