I would like to implement a functionality - that validates Kubernetes deployment files(deployments yaml or service yaml or rc yaml) using k8s JSON schema /Yaml Schema.
Currently I need the setup kubectl and k8s cluster available in order to validate. But without this set up , would like to validate using Go-Client (K8s) api.
Can anyone tell me if there are any libraries that I can use to validate the files?How can I obtains the K8s schemas. are there any tools/libraries to generate schemas ? can you point me the direction, since I am totally new to kubernetes stuff.
Does anyone know how kubectl implements this? I would like to use similar libraries if possible
Yes, use Kubernetes JSON Schemas.
To validate your Kubernetes schema without having a connection to your cluster you can use two OSS tools:
I know that kubeconform can also be imported as a Go Module, I don't know if this is the case with kubeval.
If you want to learn more about the differences between the two tools and running schema validation with kubectl --dry-run
, you can check out the blog post that I wrote on this topic - A Deep Dive Into Kubernetes Schema Validation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With