Skip to content

Latest commit

 

History

History
105 lines (80 loc) · 3.37 KB

using-kubelinter.md

File metadata and controls

105 lines (80 loc) · 3.37 KB

Using KubeLinter

You can run KubeLinter both locally and on your CI systems.

Running locally

After you've installed KubeLinter, use the lint command and provide:

** Kubernetes **

  • The path to your Kubernetes yaml file:
    kube-linter lint /path/to/yaml-file.yaml
  • The path to a directory containing your Kubernetes yaml files:
    kube-linter lint /path/to/directory/containing/yaml-files/

** Helm **

The path to a directory containing the Chart.yaml file:

kube-linter lint /path/to/directory/containing/Chart.yaml-file/

[!NOTE] To get structured output, use the --format option. For example,

  • Use --format=json to get the output in JSON format.
  • Use --format=sarif to get the output in the SARIF spec.

Using KubeLinter with the pre-commit framework

If you are using the pre-commit framework for managing Git pre-commit hooks, you can install and use KubeLinter as a pre-commit hook. To do this, add the following to your .pre-commit-config.yaml:

  - repo: https://github.com/stackrox/kube-linter
    rev: 0.6.0 # kube-linter version 
    hooks:
        # You can change this to kube-linter-system or kube-linter-docker
      - id: kube-linter

The .pre-commit-hooks.yaml includes the following pre-commit hooks:

  1. kube-linter: Clones, builds, and installs KubeLinter locally (by using go get).
  2. kube-linter-system: Runs the KubeLinter binary.
    • You must install KubeLinter and add it to your path before running this pre-commit hook.
  3. kube-linter-docker: Pulls the KubeLinter docker image, mounts the project directory in the container, and runs the kube-linter command.

KubeLinter commands

This section covers kube-linter command syntax, describes the command operations, and provides some common command examples.

Commands syntax

Use the following syntax to run KubeLinter commands:

kube-linter [resource] [command] [options]

where resource, command, and options are:

  • resource specifies the resources on which you want to perform operations. For example, checks or templates.
  • command specifies the operation that you want to perform, for example, kube-linter lint. Or the operation you want to perform on a specified resource, for example, kube-linter checks list.
  • options specifies options for each command. For example, you can use the -c or --config option to specify a configuration file.

Viewing help

Use the --help (or -h) option to get a complete list of resources and commands. The --help option lists CLI reference information about available resources, commands, and their options.

For example,

  • to find all resources, run the following command:
    kube-linter --help
  • to find available commands for a specific resource, run the following command:
    kube-linter checks --help
  • to find available options for a specific command, run the following command:
    kube-linter lint --help