Client side validations of Kubernetes manifests
To be honest writing Kubernetes manifests can be tedius and it prone to misconfiguration. Of course it will in the end be validated server side, but we would like to avoid most errors before we hand off the manifests to the API server. This can be particular helpful when utilizing GitOps, since the changes will be consumed asynchronous. To achieve this will use the following tooling:
Let's start with kustomize and make sure that we can actually build our manifest bundle.
We can now add this to .pre-commit-config.yaml file to the root of the project to have it run every time we commit.
Now on to kubeconform for validating our manifests.
We of course depend on the CRDs catalog having our CRs and them being updated, but it is relatively easy to contribute to the catalog see PRs #453 and #600.
We can now also add this to our pre-commit config file like so.
Using pre-commit is nice to validate your commits, but it requires everybody to install it and running pre-commit install. So to enforce above validations we can add a CI step in the form of a Github action.
This setup is not bullet proof, but it do add some extra confidence and it is very low effort to get going.
-
This action is in maintenance-only mode and you should support the project by using pre-commit.ci instead. But so that everyone can follow the other option is used. ↩