Using kubeval :)
kubeval
is a tool for validating a Kubernetes YAML or JSON configuration file. It does so using schemas generated from the Kubernetes OpenAPI specification, and therefore can validate schemas for multiple versions of Kubernetes.Installation
Download kubeval here: https://github.com/instrumenta/kubeval/releases
Example.
Suppose we have the following k8s-example.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
We can check it with the following command:
$ kubeval k8s-example.yaml
PASS - k8s-example.yaml contains a valid Deployment (nginx-deployment)
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
$ kubeval k8s-example.yaml
WARN - k8s-example.yaml contains an invalid Deployment (nginx-deployment) - spec.template: Invalid type. Expected: object, given: null
No comments:
Post a Comment