Skip to main content
Version: 3.9.0

How to Collect Kubernetes Resource Data

The Kubernetes collector is configured within the Resoto Worker configuration via the config command in Resoto Shell.

Prerequisites​

This guide assumes that you have already installed Resoto.

Directions​

1. Enable the Kubernetes Collector​

  1. Open the Resoto Worker configuration via the config command in Resoto Shell:

    > config edit resoto.worker
  2. Add k8s to the list of collectors by modifying the configuration as follows:

    Resoto Worker configuration
    resotoworker:
    ...
    # List of collectors to run
    collector:
    - 'k8s'
    ...
    ...

2. Authenticate with Kubernetes​

You can authenticate with Kubernetes via kubeconfig files, manual configuration, or both.

The easiest way to configure access to Kubernetes is via kubeconfig files.

  1. Open the Resoto Worker configuration via the config command in Resoto Shell:

    > config edit resoto.worker
  2. Add the content of kubeconfig file(s) to the resotoworker section as follows:

    Resoto Worker configuration
    resotoworker:
    ...
    write_files_to_home_dir:
    - path: ~/.kube/config_1
    content: |
    apiVersion: v1
    clusters:
    - cluster:
    certificate-authority-data: <ca_data>
    server: https://k8s.example.com
    name: example-cluster
    contexts:
    - context:
    cluster: example-cluster
    user: k8s-admin
    name: context1
    current-context: context1
    kind: Config
    preferences: {}
    users:
    - name: k8s-admin
    user:
    token: <token>
    - path: ~/.kube/config_2
    content: ...
    ...
    ...
    note

    If you do not wish to save the contents of your kubeconfig file(s) to Resoto's database, you can alternatively mount the directory containing your kubeconfig file(s) to the resotoworker container.

    info

    Since Resoto is running on your local machine, it can access the file(s) directly. Move or copy your kubeconfig file(s) to the ~/.kube directory.

  3. Modify the k8s section of the configuration as follows, defining path and contexts for each file:

    Resoto Worker configuration
    resotoworker:
    ...
    ...
    k8s:
    config_files:
    - path: "/home/resoto/.kube/config_1"
    all_contexts: false
    contexts: ["context1", "context2"]
    - path: "/home/resoto/.kube/config_2"
    all_contexts: true
    note

    The above example assumes that your kubeconfig file(s) are named config_1, config_2, etc.

    info

    If a single kubeconfig file holds multiple contexts, it is possible to restrict the contexts to be used by defining them explicitly. Setting all_contexts to true will not filter, resulting in taking all found contexts.

3. Trigger Resource Collection​

By default, Resoto performs resource collection each hour. To immediately trigger a collect run, use the workflow run command in Resoto Shell:

> workflow run collect

Once the collect run completes, you can view a summary of collected Kubernetes resources using the following search:

> search is(kubernetes_resource) | count kind

Contact Us

Have feedback or need help? Don’t be shy—we’d love to hear from you!

 

 

 

Some Engineering Inc.