Home > Software design >  How to collect Kubernetes Metadata?
How to collect Kubernetes Metadata?

Time:11-16

I am looking for a way to get all object's metadata within a k8s cluster and send it out to an external server.

By metadata, I refer to objects Name, Kind, Labels, Annotations, etc. The intention is to build an offline inventory of a cluster.

What would be the best approach to build it? is there any tool that already does something similar?

Thanks

CodePudding user response:

Try this commands

kubectl get all --all-namespaces -o yaml

or

kubectl get all --all-namespaces -o json

you can parse and use as you find fit

CodePudding user response:

Posting this as a community wiki, feel free to edit and expand.


There are different ways to achieve it.

  1. From this GitHub issue comment it's possible to iterate through all resources to get all available objects.

    in yaml:

    kubectl api-resources --verbs=list -o name   | xargs -n 1 kubectl get --show-kind --ignore-not-found -o yaml
    

    in json:

    kubectl api-resources --verbs=list -o name   | xargs -n 1 kubectl get --show-kind --ignore-not-found -o json
    

    And then parse the output.

  2. Use kubernetes clients.

    There are already developed kubernetes clients (available for different languages) which can be used to get required information and work with it later.

  3. Use kubectl plugin - ketall (didn't test it)

    There's a developed plugin for kubectl which returns all cluster resources. Please find github repo - ketall. Again after cluster objects are gotten, you will need to parse/work with them.

  • Related