This repository contains a set of schemas for most recent Kubernetes versions. For each specified Kubernetes versions you should find four different flavours:
- vX.Y.Z - URL referenced based on the specified GitHub repository
- vX.Y.Z-standalone - de-referenced schemas, more useful as standalone documents
- vX.Y.Z-local - relative references, useful to avoid the network dependency
- vX.Y.Z-strict - prohibits properties not defined in the schema
Note that the Kubernetes API allows additional properties to be submitted,
but kubectl
acts like the strict flavour above.
Here are the links to the deployment
schemas for Kubernetes 1.20.0:
- v1.20.0/deployment.json
- v1.20.0-standalone/deployment.json
- v1.20.0-local/deployment.json
- v1.20.0-standalone-strict/deployment.json
There are lots of use cases for these schemas, they are primarily useful as a low-level part of other developer workflow tools. But at a most basic level you can validate a Kubernetes definition.
Here is a very simply example using the Python jsonschema client and an invalid deployment file:
$ jsonschema -F "{error.message}" -i hello-nginx.json v1.20.0-standalone/deployment.json
u'template' is a required property
As noted these schemas have lots of potential uses for development tools. Here are a few ideas, some of which I've been hacking on:
- Demonstrating using with the more common YAML serialisation
- Testing tools to show your Kubernetes configuration files are valid, and against which versions of Kubernetes
- Migration tools to check your config files are still valid against master or beta releases
- Integration with code editors, for instance via something like Schema Store
- Validation of Kubernetes configs generated by higher-level tools, like Helm, Ksonnet or Puppet
- Visual tools for crafting Kubernetes configurations
- Tools to show changes between Kubernetes versions
$ kubeval --strict --schema-location https://raw.githubusercontent.com/Onemind-Services-LLC/kubernetes-json-schema/master/schema deployment.yaml
PASS - deployment.yaml contains a valid Deployment
The tooling for generating these schemas is openapi2jsonschema. It's not Kubernetes specific and should work with other OpenAPI APIs too. This should be useful if you're using a pre-release or otherwise modified version of Kubernetes, or something like OpenShift which extends the standard APIs with additional types.
This is a fork from https://github.com/instrumenta/kubernetes-json-schema