Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate Kubernetes Configuration files(YAML)

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

like image 805
dkat Avatar asked Aug 09 '17 11:08

dkat


2 Answers

Yes, use Kubernetes JSON Schemas.

like image 95
Michael Hausenblas Avatar answered Sep 17 '22 15:09

Michael Hausenblas


To validate your Kubernetes schema without having a connection to your cluster you can use two OSS tools:

  • kubeval
  • kubeconform

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

like image 37
eyarz Avatar answered Sep 20 '22 15:09

eyarz