title: How can I list all pods in a kubernetes cluster in Python?
body: <p>I'm trying to replicate the <code>kubectl get pods</code> command in Python3 using the <a href="https://github.com/kubernetes-client/python" rel="nofollow noreferrer">kubernetes python library</a>. Except, I'm working with a remote kubernetes cluster, NOT my localhost. The configuration host is a particular web address.</p>
  <p>Here's what I tried:</p>
  <pre><code>    v1 = kubernetes.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>As recommended in the <a href="https://github.com/kubernetes-client/python" rel="nofollow noreferrer">documentation</a>. This however defaults to searching my localhost instead of the specific web address. I know I have access to this web address because the following runs totally 100% as expected:</p>
  <pre><code>import time
  import kubernetes.client
  from kubernetes.client.rest import ApiException
  from pprint import pprint
  
  configuration = kubernetes.client.Configuration()
  # Configure API key authorization: BearerToken
  configuration.api_key['authorization'] = 'YOUR_API_KEY'
  # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
  configuration.api_key_prefix['authorization'] = 'Bearer'
  
  # Defining host is optional and default to http://localhost
  configuration.host = &quot;THE WEB HOST I'M USING&quot;
  
  # Enter a context with an instance of the API kubernetes.client
  with kubernetes.client.ApiClient(configuration) as api_client:
      # Create an instance of the API class
      api_instance = kubernetes.client.AdmissionregistrationApi(api_client)
      
      try:
          api_response = api_instance.get_api_group()
          pprint(api_response)
      except ApiException as e:
          print(&quot;Exception when calling AdmissionregistrationApi-&gt;get_api_group: %s\n&quot; % e)
  </code></pre>
  <p>What do you all think? How do I force it to check the pods of that host getting around the <code>localhost</code> default?</p>