<p>I would like to write a small programm similar to <code>kubectl explain</code>.</p>
<p>I use the python client.</p>
<p>With <code>kubectl explain pods -v=8</code> I see which APIs get called.</p>
<p>The URL is <code>/openapi/v2</code></p>
<p>I tried this:</p>
<pre><code>from kubernetes import client, config

# Configs can be set in Configuration class directly or using helper utility
from kubernetes.client import ApiClient

config.load_kube_config()

print(ApiClient().call_api('/openapi/v2', method='GET'))
</code></pre>
<p>But the result is empty:</p>
<pre><code>(None, 200, HTTPHeaderDict({'Accept-Ranges': 'bytes', 'Audit-Id': '5f025f01-cab9-4816-8579-751b47604275', 'Cache-Control': 'no-cache, private', 'Content-Length': '3315308', 'Content-Type': 'text/plain; charset=utf-8', 'Etag': '&quot;194A5412D92C8239FAA388BD61A2729940609093EE00703602A983C97E2D7FD9FFA0E25F481A2659782EC80339F6A25CD9FD414B8D652409E1B521BB4F53E5DB&quot;', 'Last-Modified': 'Thu, 31 Mar 2022 17:51:05 GMT', 'Vary': 'Accept-Encoding, Accept', 'X-Kubernetes-Pf-Flowschema-Uid': 'f70aa7db-e8d7-4690-becf-40ac57d88c1f', 'X-Kubernetes-Pf-Prioritylevel-Uid': '5c900157-e070-46c3-b774-a77dfa6128bc', 'Date': 'Sat, 02 Apr 2022 21:29:56 GMT'}))
</code></pre>
<p>How can I get the nice docs which <code>kubectl explain</code> shows via Python?</p>

guettli
<p>You're already getting the data, it's just that some error occurs while processing it :)
To turn off post-processing, you need to pass the _preload_content=False argument to call_api<br />
Then the code will look something like this:</p>
<pre><code>import json
from kubernetes import client, config

# Configs can be set in Configuration class directly or using helper utility
from kubernetes.client import ApiClient

config.load_kube_config()

apiClient = ApiClient()
answer = apiClient.call_api('/openapi/v2', method='GET', _preload_content=False)
data = json.loads(answer[0].data)
print(data)
</code></pre>
<p>If you only want to get the description, you can use curl like this with Bearer Auth:
<a href="https://blog.ronnyvdb.net/2019/08/07/howto-curl-the-kubernetes-api-server" rel="nofollow noreferrer">https://blog.ronnyvdb.net/2019/08/07/howto-curl-the-kubernetes-api-server</a></p>
<pre><code> curl -s $APISERVER/openapi/v2 --header &quot;Authorization: Bearer $TOKEN&quot; --cacert ca.crt
</code></pre>
<p>Or with TSL Auth:</p>
<pre><code> curl -s $APISERVER/openapi/v2 --cert client.crt --key client.key --cacert ca.crt
</code></pre>
<p>After that, you can use the tools to work with the openAPI description: <a href="https://openapi.tools" rel="nofollow noreferrer">https://openapi.tools</a></p>
<p>For example, upload json to <a href="https://mrin9.github.io/OpenAPI-Viewer" rel="nofollow noreferrer">https://mrin9.github.io/OpenAPI-Viewer</a> and enjoy</p>
