<p>I am looking for a way to get all object's metadata within a k8s cluster and send it out to an external server.</p>
<p>By metadata, I refer to objects <code>Name</code>, <code>Kind</code>, <code>Labels</code>, <code>Annotations</code>, etc.
The intention is to build an offline inventory of a cluster.</p>
<p>What would be the best approach to build it? Is there any tool that already does something similar?</p>
<p>Thanks</p>

tomikos
<p>Posting this as a community wiki, feel free to edit and expand.</p>
<hr />
<p>There are different ways to achieve it.</p>
<ol>
<li><p>From this <a href="https://github.com/kubernetes/kubectl/issues/151#issuecomment-402003022" rel="nofollow noreferrer">GitHub issue comment</a> it's possible to iterate through all resources to get all available objects.</p>
<p>in <strong>yaml</strong>:</p>
<pre><code>kubectl api-resources --verbs=list -o name   | xargs -n 1 kubectl get --show-kind --ignore-not-found -o yaml
</code></pre>
<p>in <strong>json</strong>:</p>
<pre><code>kubectl api-resources --verbs=list -o name   | xargs -n 1 kubectl get --show-kind --ignore-not-found -o json
</code></pre>
<p>And then parse the output.</p>
</li>
<li><p>Use kubernetes clients.</p>
<p>There are already developed <a href="https://kubernetes.io/docs/reference/using-api/client-libraries/" rel="nofollow noreferrer">kubernetes clients</a> (available for different languages) which can be used to get required information and work with it later.</p>
</li>
<li><p>Use kubectl plugin - <code>ketall</code> (didn't test it)</p>
<p>There's a developed plugin for kubectl which returns <strong>all</strong> cluster resources. Please find <a href="https://github.com/corneliusweig/ketall" rel="nofollow noreferrer">github repo - ketall</a>. Again after cluster objects are gotten, you will need to parse/work with them.</p>
</li>
</ol>
