<p>I am trying to get kubernetes api server from a pod.</p>
<p>Here is my pod configuration</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: test
spec:
  schedule: &quot;*/5 * * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: test
            image: test:v5
            env:
            imagePullPolicy: IfNotPresent
            command: ['python3']
            args: ['test.py']
          restartPolicy: OnFailure
</code></pre>
<p>And here is my kubernetes-client python code inside test.py</p>
<pre><code>from kubernetes import client, config

# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config()

v1 = client.CoreV1Api()
print(&quot;Listing pods with their IPs:&quot;)
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
    print(&quot;%s\t%s\t%s&quot; % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
</code></pre>
<p>But i am getting this error:</p>
<pre><code>kubernetes.config.config_exception.ConfigException: Invalid kube-config file. No configuration found.
</code></pre>

<p>When operating in-cluster you want <code>load_incluster_config()</code> instead.</p>
