What is KubeLinter? How to use it?
What is KubeLinter?
The KubeLinter is an open-source command-line tool to check the quality of Kubernetes objects’ configurations. It also detects any misconfigurations on Kubernetes YAML files and Helm charts. KubeLinter can be integrated into CI/CD pipelines and checks YAML files before deployment. KubeLinter has about 20 built-in rules and provides the feature to create new ones based on the environment’s needs.
How to use it?
KubeLinter does not require too many resources and can be used by running commands in different OS command lines.
Microsoft Windows
- Command Prompt
- PowerShell
Unix-like systems
- Bash
- Zsh
- Tcsh
How to install KubeLinter?
Using Brew
It is pretty simple if you have HomeBrew for macOS or LinuxBrew. KubeLinter can be installed by using the following command:
brew install kube-linter
Using the Latest Binary
You can find and download the latest binaries from the following repo. You can use these binaries in docker containers or CI pipelines.
Here’s how to download and install KubeLinter on Linux.
wget https://github.com/stackrox/kube-linter/releases/download/0.2.5/kube-linter-linux.tar.gz
tar -xvf kube-linter-linux.tar.gz
mv kube-linter /usr/local/bin/
How to use KubeLinter?
After we have done with the installation phase, we can simply type kube-linter and see the available commands. KubeLinter has five main commands:
1. checks
2. help
3. lint
4. templates
5. version
The 2nd and 5th commands already define itself 😄
The kube-linter check list
command lists built-in policies provided by KubeLinter.
Now, we can focus on the most important command to check our yaml files. lint
command allows you to check single file or multiple files in a directory. To check single file:
kube-linter lint path/to/kubelinter-example.yaml
To check multiple files in a directory:
kube-linter lint path/to/example-yaml-files/
Also, to check a single file with a specific rule:
kube-linter lint path/to/kubelinter-example.yaml --include privileged-ports
Check yaml file with all built-in rules:
kube-linter lint path/to/kubelinter-example.yaml --add-all-built-in
Example use of KubeLinter
To see the output of KubeLinter I have created a simple yaml file.
I have simply typed the following commands.
kube-linter lint kubelinter-pod.yaml
Here is the output:
All in all, taking advantage of KubeLinter, you can create secure and best practice applied yaml files for your production environment.
Documentations
You can find the official GitHub repo and other useful links below.