kubeconform in CI: typos that pass, and 'could not find schema'
kubeconform checks Kubernetes manifests against the official JSON schemas, no cluster needed. It’s quick and it fits in a CI job. It also has two ways to let broken YAML through with exit code 0.
A misspelled field is fine unless you pass -strict. And -ignore-missing-schemas, the flag people add to silence could not find schema for Certificate, silences a misspelled kind too. I ran both cases so you can see the output.
Setup
I used kubeconform v0.8.0, downloaded from the GitHub release and checked against the CHECKSUMS file from that release:
kc.tgz: OK
Everything below ran against a plain Deployment called web. It passes cleanly:
$ kubeconform -summary ok-deployment.yaml
Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0
[exit 0]
The [exit N] lines are mine, appended by the test script. kubeconform doesn’t print them. In a few outputs below I left out the Summary: line to keep them short.
What it catches with no flags
Wrong types and missing required keys. I changed replicas: 3 to replicas: "3":
bad-string-replicas.yaml - Deployment web is invalid: problem validating schema. Check JSON formatting: jsonschema validation failed with 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/master-standalone/deployment-apps-v1.json#' - at '/spec/replicas': got string, want null or integer
And I deleted the selector block:
missing-selector.yaml - Deployment web is invalid: problem validating schema. Check JSON formatting: jsonschema validation failed with 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/master-standalone/deployment-apps-v1.json#' - at '/spec': missing property 'selector'
Both exited 1. The message is long but the useful part is at the end: a JSON path and what was wrong with it. Ignore the “Check JSON formatting” prefix. It showed up on every schema failure I got, whatever the cause.
The typo that passes
Now the one that bites. I renamed replicas to replica, which is a one-letter slip.
$ kubeconform -summary typo-field.yaml
Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0
[exit 0]
Valid. The manifest no longer sets replicas at all, and CI went green. Whether the API server complains about an unknown field depends on how the manifest gets applied, and I didn’t test that. The default schemas allow properties they don’t list. Add -strict and kubeconform switches to the strict variant of the schemas:
$ kubeconform -strict -summary typo-field.yaml
typo-field.yaml - Deployment web is invalid: problem validating schema. Check JSON formatting: jsonschema validation failed with 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/master-standalone-strict/deployment-apps-v1.json#' - at '/spec': additional properties 'replica' not allowed
[exit 1]
Note the URL changed from master-standalone to master-standalone-strict. That’s the whole difference. The -h text also says -strict rejects duplicated keys. I didn’t test that part.
-strict. The commands run for real on the test machine; the typing is animated.My default is -strict in CI. If it’s noisy on an existing repo, read the findings before you drop the flag. Bicep has a similar habit of exiting 0 with warnings, which I tested in the Bicep optional parameters guide.
“could not find schema for Certificate”
Custom resources have no schema in the default location. A cert-manager Certificate:
$ kubeconform -summary crd-certificate.yaml
crd-certificate.yaml - Certificate web-tls failed validation: could not find schema for Certificate
Summary: 1 resource found in 1 file - Valid: 0, Invalid: 0, Errors: 1, Skipped: 0
[exit 1]
The tempting fix is -ignore-missing-schemas. It works:
$ kubeconform -summary -ignore-missing-schemas crd-certificate.yaml
Summary: 1 resource found in 1 file - Valid: 0, Invalid: 0, Errors: 0, Skipped: 1
[exit 0]
Look at the counts. Valid: 0. Nothing was validated, and the exit code says all is well.
The better fix is to point kubeconform at a second schema source. The kubeconform README suggests Datree’s CRDs-catalog for this:
$ kubeconform -strict -summary -schema-location default -schema-location https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json crd-certificate.yaml
Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0
[exit 0]
That time the resource really was checked. To prove it, I made dnsNames a string instead of a list:
crd-certificate-bad.yaml - Certificate web-tls is invalid: problem validating schema. Check JSON formatting: jsonschema validation failed with 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/cert-manager.io/certificate_v1.json#' - at '/spec/dnsNames': got string, want array
Two things to keep in mind. The catalog is a third-party repo, so its schema may not match the CRD version you run. And if your CRD isn’t in it, the README says you’ll have to convert the CRD’s OpenAPI schema to JSON schema yourself. I didn’t try that route.
The flag that hides typos
Here’s why I’d avoid -ignore-missing-schemas for anything beyond a quick local run. From kubeconform’s point of view, a misspelled kind is also a kind with no schema:
$ kubeconform -summary typo-kind.yaml
typo-kind.yaml - Deploymnet web failed validation: could not find schema for Deploymnet
[exit 1]
$ kubeconform -summary -ignore-missing-schemas typo-kind.yaml
Summary: 1 resource found in 1 file - Valid: 0, Invalid: 0, Errors: 0, Skipped: 1
[exit 0]
With the flag, the broken Deployment sails through. The narrower option is -skip, which takes the kind you mean to skip:
$ kubeconform -summary -skip Certificate typo-kind.yaml
typo-kind.yaml - Deploymnet web failed validation: could not find schema for Deploymnet
[exit 1]
-skip Certificate on the Certificate file gave Skipped: 1 and exit 0, as you’d expect. The typo’d kind still fails. If you can’t get a schema for a CRD, skipping that one kind by name is the less dangerous way to live without it.
-ignore-missing-schemas.Here’s the decision flow in one picture:
Pin the Kubernetes version
kubeconform validates against master unless you say otherwise. That’s the newest schema, not the version of your cluster. I validated one policy/v1beta1 PodDisruptionBudget against two versions:
$ kubeconform -summary -kubernetes-version 1.24.0 removed-api.yaml
Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0
[exit 0]
$ kubeconform -summary -kubernetes-version 1.25.0 removed-api.yaml
removed-api.yaml - PodDisruptionBudget web failed validation: could not find schema for PodDisruptionBudget
[exit 1]
Kubernetes stopped serving policy/v1beta1 PodDisruptionBudget in v1.25, per the deprecation guide. So could not find schema can also mean “this API version no longer exists in the Kubernetes version you chose”. The message doesn’t say that. Set -kubernetes-version to what your cluster runs and read this error as a hint to check apiVersion first.
A CI job for it
This is the workflow I’d start from. It pins the version, verifies the download against the release checksum, caches the schemas, and uses strict mode with the CRD catalog:
name: validate-manifests
on:
pull_request:
paths: ["k8s/**"]
permissions:
contents: read
env:
KUBECONFORM_VERSION: v0.8.0
KUBECONFORM_SHA256: 9bc2bffbf71f261128533edaf912153948b7ff238f9a531ae6d34466ec287883
K8S_VERSION: 1.31.0
jobs:
kubeconform:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install kubeconform
run: |
curl -sSfLo kc.tgz "https://github.com/yannh/kubeconform/releases/download/${KUBECONFORM_VERSION}/kubeconform-linux-amd64.tar.gz"
echo "${KUBECONFORM_SHA256} kc.tgz" | sha256sum -c -
tar xzf kc.tgz kubeconform
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .schema-cache
key: kubeconform-schemas-${{ env.K8S_VERSION }}
- name: Validate
run: |
mkdir -p .schema-cache
./kubeconform -strict -summary \
-kubernetes-version "${K8S_VERSION}" \
-cache .schema-cache \
-schema-location default \
-schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json' \
k8s/
I ran the file through actionlint (it printed nothing and exited 0), and ran the Validate step locally on two good manifests: 2 resources found in 2 files - Valid: 2. I did not run it on GitHub. If you want a second opinion on workflows in general, the actionlint guide covers that.
Two details in there are not decoration:
- The
mkdir -pis needed. Pointing-cacheat a folder that doesn’t exist fails instead of creating it:failed opening cache folder ../work/cache: stat ../work/cache: no such file or directory. - The cache is worth having. With the network cut off (I pointed
HTTPS_PROXYat a dead port), a warm cache still passed. A cold run failed withfailed downloading schema ... giving up after 3 attempt(s). Without a cache, a GitHub hiccup fails your PR check.
What it still can’t tell you
kubeconform checks shape, not meaning. My last test: a Deployment whose selector says app: web while the pod template is labelled app: api.
$ kubeconform -strict -summary selector-mismatch.yaml
Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0
[exit 0]
Valid, because each field has the right type. The Deployment docs say .spec.selector must match the template labels or the API rejects it. I couldn’t confirm that here since I had no cluster, so treat it as the documented behaviour. The usual way to catch it is a server-side dry run against a real cluster. I didn’t run one, and kubeconform won’t flag it.