Skip to content
LatchkeyLatchkey home

kube-linter: Configure Checks with .kube-linter.yaml

A .kube-linter.yaml file under the checks and customChecks keys controls exactly which built-in checks run and lets you define new ones.

The default check set is opinionated. A config file makes the linting policy explicit and version-controlled, so it is identical in CI and on every developer machine.

What it does

The config has a checks block (with addAllBuiltIn, doNotAutoAddDefaults, include, exclude) and a customChecks block for templated checks. kube-linter reads it via --config, or finds .kube-linter.yaml in the working directory.

Common usage

.kube-linter.yaml
# .kube-linter.yaml
checks:
  addAllBuiltIn: true
  exclude:
    - "default-service-account"
    - "no-anti-affinity"
customChecks:
  - name: require-team-label
    template: required-label
    params:
      key: team

Options

KeyWhat it does
checks.addAllBuiltInStart from every built-in check
checks.doNotAutoAddDefaultsDo not auto-enable the default set
checks.include / excludeTurn specific checks on or off
customChecksDefine checks from a template + params
templateBuilt-in template a custom check derives from

In CI

Pin the config in the repo and pass --config .kube-linter.yaml so a new built-in check in a tool upgrade does not suddenly break every build. Roll new checks out as warnings first, then promote to failing once the codebase is clean.

Common errors in CI

unknown check "<name>" in include/exclude is a name mismatch; the canonical list is kube-linter checks list. error unmarshaling configuration: ... field <x> not found means a typo or wrong indentation in the YAML. A custom check with template: <unknown> fails with invalid template; valid templates are listed by kube-linter templates list.

Using this in CI

A runner has no kubeconfig, no cached context, and no interactive auth. Every kubectl invocation in CI needs the context supplied explicitly, and most confusing CI failures here are the command running against the wrong cluster or no cluster at all.

Terminal
# never rely on the ambient context on a runner
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" get pods

# confirm what you are actually connected to before mutating anything
kubectl config current-context
kubectl cluster-info

# fail fast instead of hanging on an unreachable API server
kubectl --request-timeout=30s get nodes

Frequently asked questions

kube-linter: Configure Checks with .kube-linter.yaml?
The default check set is opinionated. A config file makes the linting policy explicit and version-controlled, so it is identical in CI and on every developer machine.
What it does?
The config has a checks block (with addAllBuiltIn, doNotAutoAddDefaults, include, exclude) and a customChecks block for templated checks. kube-linter reads it via --config, or finds .kube-linter.yaml in the working directory.
In CI?
Pin the config in the repo and pass --config .kube-linter.yaml so a new built-in check in a tool upgrade does not suddenly break every build. Roll new checks out as warnings first, then promote to failing once the codebase is clean.
Common errors in CI?
unknown check "<name>" in include/exclude is a name mismatch; the canonical list is kube-linter checks list. error unmarshaling configuration: ... field <x> not found means a typo or wrong indentation in the YAML. A custom check with template: <unknown> fails with invalid template; valid templates are listed by kube-linter templates list.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card