Skip to main content

How to Collect Kubernetes Resource Data

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

Prerequisites

This guide assumes that you have already installed Fix Inventory.

Directions

1. Enable the Kubernetes Collector

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

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

    Fix Inventory Worker configuration
    fixworker:
    ...
    # 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 Fix Inventory Worker configuration via the config command in Fix Inventory Shell:

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

    Fix Inventory Worker configuration
    fixworker:
    ...
    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 Fix Inventory's database, you can alternatively mount the directory containing your kubeconfig file(s) to the fixworker container.

    info

    Since Fix Inventory 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:

    Fix Inventory Worker configuration
    fixworker:
    ...
    ...
    k8s:
    config_files:
    - path: "/home/fixinventory/.kube/config_1"
    all_contexts: false
    contexts: ["context1", "context2"]
    - path: "/home/fixinventory/.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, Fix Inventory performs resource collection each hour. To immediately trigger a collect run, use the workflow run command in Fix Inventory 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