<p>Using kubectl, it's possible, but extremely slow to get a complete list of resources within a Kubernetes namespace.  This is easy enough to do, but too slow for what I need to do.</p>

<p>I'd prefer to use the <a href="https://kubernetes.io/docs/reference/using-api/client-libraries/" rel="nofollow noreferrer">python or golang clients</a> to do what kubectl is doing on my behalf.  But <a href="https://github.com/kubernetes-client/python/blob/master/kubernetes/README.md" rel="nofollow noreferrer">the API docs are, well, generated by a machine</a>, and good for nothing other than another machine :-) You'd think there'd be an example for something this simple, but alas, there isn't.</p>

<p>I know that using kubectl and <strike>scotch tape</strike> and bash shell that I can do the following:</p>

<pre><code>#! /bin/bash

NAMESPACE=${1:-default}

kubectl get ns $NAMESPACE  &gt; /dev/null 2&gt;&amp;1 || {
   echo $0: Namespace $NAMESPACE was not found &gt;&amp;2
   exit 1
}

for type in $(kubectl  api-resources -o name --namespaced=true --no-headers --verbs=list)
do
  for item in $(kubectl -n $NAMESPACE get $type --ignore-not-found --show-kind --no-headers -o name | grep -v events.k8s.io | grep -v event)
  do
    echo $item
  done
done
</code></pre>

<p>How would this be done using the very procedural python client for kubernetes?</p>

Torenware Networks
<p>Maybe this is what you were looking for:</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()
for api in client.ApisApi().get_api_versions().groups:
    versions = []
    for v in api.versions:
        name = &quot;&quot;
        if v.version == api.preferred_version.version and len(
                api.versions) &gt; 1:
            name += &quot;*&quot;
        name += v.version
        versions.append(name)
    print(&quot;%-40s %s&quot; % (api.name, &quot;,&quot;.join(versions)))
</code></pre>
<p>Taken from here: <a href="https://github.com/kubernetes-client/python/blob/master/examples/api_discovery.py" rel="nofollow noreferrer">https://github.com/kubernetes-client/python/blob/master/examples/api_discovery.py</a></p>
