Tool to check YAML files for Kubernetes offline

11/25/2019

Is there some tool available that could tell me whether a K8s YAML configuration (to-be-supplied to kubectl apply) is valid for the target Kubernetes version without requiring a connection to a Kubernetes cluster?

One concrete use-case here would be to detect incompatibilities before actual deployment to a cluster, just because some already-deprecated label has been finally dropped in a newer Kubernetes version, e.g. as has happened for Helm and the switch to Kubernetes 1.16 (see Helm init fails on Kubernetes 1.16.0):

Dropped:

apiVersion: extensions/v1beta1

New:

apiVersion: apps/v1

I want to check these kind of incompatibilities within a CI system, so that I can reject it before even attempting to deploy it.

-- enote-kane
continuous-integration
kubernetes

1 Answer

11/25/2019

just run below command to validate the syntax

kubectl create -f <yaml-file> --dry-run

In fact the dry-run option is to validate the YAML syntax and the object schema. You can grab the output into a variable and if there is no error then rerun the command without dry-run

-- P Ekambaram
Source: StackOverflow