Skip to main content

Containers and Kubernetes · Beginner · 25 min

Validate Kubernetes manifests before they reach a cluster

By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · kubectl 1.37.3 · kubeconform 0.8.0 · kube-linter 0.8.3 · Helm 4.3.2

You will have one script that checks plain, Kustomize, Helm, generated and custom-resource manifests against the Kubernetes 1.37 schemas and a set of lint rules, with no cluster, and a GitHub Actions job that runs it on every pull request.

On this page

A Kubernetes manifest can be valid YAML and still be wrong. Type replica: 3 instead of replicas: 3 and kubectl apply rejects the unknown field, but only at apply time against a live cluster. Other clients, such as raw API calls, some controllers and GitOps tools, get only a warning or have the field silently dropped, and the Deployment runs one pod. Forget a memory limit and nothing complains until a node runs out of memory. Most teams find these problems after kubectl apply, which is the slowest and most expensive place to find them.

This tutorial moves the checks earlier, onto your laptop and into CI, where they need no cluster at all. You will use two tools that do different jobs:

  • kubeconform checks each object against the JSON schemas generated from the Kubernetes API. It answers "would the API server accept this shape?": field names, types, required fields.
  • kube-linter checks objects against good-practice rules. It answers "should I run this?": probes, resource requests and limits, containers running as root.

You will run both against a small app called notes in four forms: a plain YAML file, a Kustomize overlay, a Helm chart and manifests generated by kubectl, plus a Gateway API custom resource. At the end, one script runs every check and a GitHub Actions job runs that script. Everything lives in ~/manifest-check-demo, so you can delete it when you are done.

Step 1 · Install the tools with a script

Put the installer in a script rather than typing it, because the CI job in the last step reuses it, and the same versions then run on your laptop and in CI. It works on Linux and macOS, on Intel and Arm. It checks kubectl, kubeconform and Helm against their published checksums before installing anything:

Bash
mkdir -p ~/manifest-check-demo
cd ~/manifest-check-demo
cat > install-tools.sh <<'SH'
#!/usr/bin/env bash
# Installs pinned kubectl, kubeconform, kube-linter and Helm into /usr/local/bin.
set -euo pipefail
KUBECTL=1.37.3
KUBECONFORM=0.8.0
KUBE_LINTER=0.8.3
HELM=4.3.2

OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
case "$(uname -m)" in
  x86_64) ARCH=amd64 ;;
  aarch64|arm64) ARCH=arm64 ;;
  *) echo "No release for CPU type $(uname -m)" >&2; exit 1 ;;
esac
if command -v sha256sum >/dev/null; then SUM="sha256sum"; else SUM="shasum -a 256"; fi

WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
cd "$WORK"

curl -fsSLO "https://dl.k8s.io/release/v${KUBECTL}/bin/${OS}/${ARCH}/kubectl"
curl -fsSLO "https://dl.k8s.io/release/v${KUBECTL}/bin/${OS}/${ARCH}/kubectl.sha256"
echo "$(cat kubectl.sha256)  kubectl" | $SUM -c

curl -fsSLO "https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM}/kubeconform-${OS}-${ARCH}.tar.gz"
curl -fsSLO "https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM}/CHECKSUMS"
grep " kubeconform-${OS}-${ARCH}.tar.gz$" CHECKSUMS | $SUM -c
tar xzf "kubeconform-${OS}-${ARCH}.tar.gz" kubeconform

curl -fsSLO "https://get.helm.sh/helm-v${HELM}-${OS}-${ARCH}.tar.gz"
curl -fsSLO "https://get.helm.sh/helm-v${HELM}-${OS}-${ARCH}.tar.gz.sha256sum"
$SUM -c "helm-v${HELM}-${OS}-${ARCH}.tar.gz.sha256sum"
tar xzf "helm-v${HELM}-${OS}-${ARCH}.tar.gz"

KL_SUFFIX=""
if [ "$ARCH" = arm64 ]; then KL_SUFFIX="_arm64"; fi
curl -fsSLo kube-linter "https://github.com/stackrox/kube-linter/releases/download/v${KUBE_LINTER}/kube-linter-${OS}${KL_SUFFIX}"

chmod +x kubectl kube-linter
sudo install -m 0755 kubectl kubeconform kube-linter "${OS}-${ARCH}/helm" /usr/local/bin/
SH
chmod +x install-tools.sh
./install-tools.sh

Each checksum line ends in OK. If one prints FAILED, stop: the file is damaged or not what the project published. kube-linter does not publish a checksum file; its release ships a Sigstore bundle beside each binary instead, which you can check with cosign as /tutorials/sign-and-verify-container-images-with-cosign shows.

These binaries get no updates from apt or Homebrew. To upgrade, change the four version lines at the top of the script and run it again; CI picks up the change from the same file.

On a prepaid or metered connection, note that each run downloads about 150 MB: the script works in a fresh temporary folder and deletes it on exit, so running it again downloads every tool again. The CI job in the last step does the same on every run; only the kubeconform schemas are cached there.

Check it worked

Bash
kubectl version --client
kubeconform -v
kube-linter version
helm version --short

You see Client Version: v1.37.3, v0.8.0, 0.8.3 and a line starting v4.3.2.

Step 2 · Catch typos with kubeconform -strict

Write a Deployment and a Service for notes. The Deployment has a deliberate typo, replica: where Kubernetes expects replicas:. The image name uses registry.example.test, a name reserved for examples; nothing here pulls it, so replace it with your own image when you reuse the files.

Bash
mkdir -p ~/manifest-check-demo/base ~/.cache/kubeconform
cd ~/manifest-check-demo
cat > base/notes.yaml <<'YAML'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: notes
  labels:
    app.kubernetes.io/name: notes
spec:
  replica: 2
  selector:
    matchLabels:
      app.kubernetes.io/name: notes
  template:
    metadata:
      labels:
        app.kubernetes.io/name: notes
    spec:
      containers:
        - name: notes
          image: registry.example.test/notes:1.4.2
          ports:
            - name: http
              containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: notes
spec:
  selector:
    app.kubernetes.io/name: notes
  ports:
    - name: http
      port: 80
      targetPort: http
YAML

Run kubeconform without -strict first. -kubernetes-version picks the schemas for the cluster you deploy to, and -cache keeps the downloaded schemas on disk so later runs work offline and cost no data:

Bash
cd ~/manifest-check-demo
kubeconform -summary -kubernetes-version 1.37.3 -cache ~/.cache/kubeconform base/notes.yaml

It reports both resources as valid. The plain schemas allow fields they do not know about. kubectl rejects unknown fields by default, but only when it reaches a live cluster; clients that do not ask the API server for strict validation, such as some GitOps tools or kubectl --validate=warn, get a warning or have the field dropped. That is exactly how a typo slips through. Now add -strict, which rejects unknown fields and duplicate keys:

Bash
cd ~/manifest-check-demo
if kubeconform -strict -summary -kubernetes-version 1.37.3 -cache ~/.cache/kubeconform base/notes.yaml > strict.txt; then
  echo "the typo was not caught"; false
fi
cat strict.txt
grep "additional properties 'replica' not allowed" strict.txt

Fix the typo. This rewrites the line in place with a portable command, then runs the strict check again:

Bash
cd ~/manifest-check-demo
awk '{ sub(/^  replica: 2$/, "  replicas: 2"); print }' base/notes.yaml > base/notes.yaml.new
mv base/notes.yaml.new base/notes.yaml
kubeconform -strict -summary -kubernetes-version 1.37.3 -cache ~/.cache/kubeconform base/notes.yaml
rm -f strict.txt

Check it worked

The failing run names the Deployment and ends with additional properties 'replica' not allowed, and its summary counts Invalid: 1. After the fix the summary reads Summary: 2 resources found in 1 file - Valid: 2, Invalid: 0, Errors: 0, Skipped: 0. Use -strict every time; there is no good reason to leave it off.

Step 3 · Find risky settings with kube-linter

The manifest is now valid, and it is still not ready to run. It has no health probes, no resource requests or limits, and nothing stops the container running as root. kubeconform cannot see this, because none of those fields is required. kube-linter can.

Most of its checks are on by default. The probe checks are not, so turn them on in a .kube-linter.yaml file. kube-linter reads that file from the current folder; passing --config as well makes it obvious which rules ran:

Bash
cd ~/manifest-check-demo
cat > .kube-linter.yaml <<'YAML'
checks:
  include:
    - no-liveness-probe
    - no-readiness-probe
YAML
if kube-linter lint --config .kube-linter.yaml base/notes.yaml > lint.txt 2>&1; then
  echo "kube-linter found nothing"; false
fi
cat lint.txt
grep -o 'check: [a-z-]*' lint.txt | sort -u

Each finding is one line: the file, the object, what is wrong, the check name and a short remediation. The last command lists the checks that fired. Expect at least these:

  • no-liveness-probe and no-readiness-probe: Kubernetes cannot tell when the app is stuck or not ready for traffic.
  • unset-cpu-requirements and unset-memory-requirements: no CPU request and no memory limit, so the scheduler places the pod blind and one leak can starve its neighbours.
  • run-as-non-root and no-read-only-root-fs: the container may run as root and write anywhere in its filesystem.
  • no-anti-affinity: with two or more replicas, both may land on the same node, and one node failure takes the app down.

Rewrite the manifest with each of those fixed. The app is assumed to serve /healthz and /readyz on its http port; change the paths to whatever yours serves. The emptyDir on /tmp gives the app somewhere to write now that the rest of its filesystem is read-only:

Bash
cd ~/manifest-check-demo
cat > base/notes.yaml <<'YAML'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: notes
  labels:
    app.kubernetes.io/name: notes
spec:
  replicas: 2
  selector:
    matchLabels:
      app.kubernetes.io/name: notes
  template:
    metadata:
      labels:
        app.kubernetes.io/name: notes
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 10001
        runAsGroup: 10001
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              podAffinityTerm:
                topologyKey: kubernetes.io/hostname
                labelSelector:
                  matchLabels:
                    app.kubernetes.io/name: notes
      containers:
        - name: notes
          image: registry.example.test/notes:1.4.2
          ports:
            - name: http
              containerPort: 8080
          readinessProbe:
            httpGet:
              path: /readyz
              port: http
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
            periodSeconds: 20
          resources:
            requests:
              cpu: 100m
              memory: 64Mi
            limits:
              memory: 128Mi
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop: ["ALL"]
          volumeMounts:
            - name: tmp
              mountPath: /tmp
      volumes:
        - name: tmp
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: notes
spec:
  selector:
    app.kubernetes.io/name: notes
  ports:
    - name: http
      port: 80
      targetPort: http
YAML
kube-linter lint --config .kube-linter.yaml base/notes.yaml
kubeconform -strict -summary -kubernetes-version 1.37.3 -cache ~/.cache/kubeconform base/notes.yaml
rm -f lint.txt

There is no CPU limit on purpose. A CPU limit throttles the app even when the node has spare CPU, and kube-linter's default rule asks only for a CPU request; /tutorials/set-cpu-and-memory-requests-and-limits explains the trade-off.

When a rule does not fit one object, do not switch it off for everything. Add an annotation to that object with the reason as its value, for example ignore-check.kube-linter.io/no-read-only-root-fs: "Legacy app writes to /var/cache; tracked in issue 42", so the exception is visible in review.

Check it worked

The first run exits with an error and a line like Error: found 7 lint errors (the exact count depends on the rules in your kube-linter version). After the rewrite, kube-linter prints No lint errors found! and exits 0, and kubeconform still reports Valid: 2.

Step 4 · Check what Kustomize and Helm render

A Kustomize overlay or a Helm chart is not a manifest. It is a recipe for one, and the mistakes that matter often appear only after rendering: a patch that adds a misspelt field, a value that turns into the wrong type. So render first and check the output, never the source files.

Start with a Kustomize base and a production overlay that changes the namespace and the replica count. kubectl kustomize renders it with the copy of Kustomize built into kubectl:

Bash
mkdir -p ~/manifest-check-demo/overlays/prod ~/manifest-check-demo/rendered
cd ~/manifest-check-demo
cat > base/kustomization.yaml <<'YAML'
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - notes.yaml
YAML
cat > overlays/prod/kustomization.yaml <<'YAML'
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: notes-prod
resources:
  - ../../base
replicas:
  - name: notes
    count: 3
YAML
kubectl kustomize overlays/prod > rendered/prod.yaml
kubeconform -strict -summary -kubernetes-version 1.37.3 -cache ~/.cache/kubeconform rendered/prod.yaml

Now a small Helm chart for the same Deployment, with the replica count and image tag as values:

Bash
mkdir -p ~/manifest-check-demo/chart/notes/templates
cd ~/manifest-check-demo
cat > chart/notes/Chart.yaml <<'YAML'
apiVersion: v2
name: notes
description: The notes web app
version: 0.1.0
appVersion: "1.4.2"
YAML
cat > chart/notes/values.yaml <<'YAML'
replicaCount: 2
image:
  repository: registry.example.test/notes
  tag: "1.4.2"
YAML
cat > chart/notes/templates/deployment.yaml <<'YAML'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}
  labels:
    app.kubernetes.io/name: notes
    app.kubernetes.io/instance: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: notes
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: notes
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 10001
        runAsGroup: 10001
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              podAffinityTerm:
                topologyKey: kubernetes.io/hostname
                labelSelector:
                  matchLabels:
                    app.kubernetes.io/name: notes
                    app.kubernetes.io/instance: {{ .Release.Name }}
      containers:
        - name: notes
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          ports:
            - name: http
              containerPort: 8080
          readinessProbe:
            httpGet:
              path: /readyz
              port: http
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
          resources:
            requests:
              cpu: 100m
              memory: 64Mi
            limits:
              memory: 128Mi
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop: ["ALL"]
YAML
helm lint chart/notes
helm template notes chart/notes > rendered/helm.yaml
kubeconform -strict -summary -kubernetes-version 1.37.3 -cache ~/.cache/kubeconform rendered/helm.yaml
kube-linter lint --config .kube-linter.yaml rendered

helm lint checks the chart's structure and that its templates render; it does not check the result against the Kubernetes schemas, which is why kubeconform runs on the output. See what happens when someone passes a value of the wrong type, a common mistake with --set:

Bash
cd ~/manifest-check-demo
helm template notes chart/notes --set replicaCount=two > bad-values.yaml
if kubeconform -strict -summary -kubernetes-version 1.37.3 -cache ~/.cache/kubeconform bad-values.yaml; then
  echo "the wrong type was not caught"; false
fi
rm -f bad-values.yaml

Helm renders replicas: two without complaint. kubeconform rejects it, because replicas must be an integer.

Check it worked

The overlay reports Valid: 2 and rendered/prod.yaml contains namespace: notes-prod and replicas: 3 (check with grep -E 'namespace:|replicas:' rendered/prod.yaml). helm lint ends with 1 chart(s) linted, 0 chart(s) failed, the chart output reports Valid: 1, and kube-linter finds no errors in either rendered file. The bad-values run reports Invalid: 1. The rendered/ folder is build output: add it to .gitignore rather than committing it.

Step 5 · Validate custom resources with the CRDs catalog

kubeconform knows only the built-in Kubernetes kinds. Give it a Gateway API HTTPRoute, a custom resource defined by a CRD, and it cannot find a schema:

Bash
mkdir -p ~/manifest-check-demo/crds
cd ~/manifest-check-demo
cat > crds/notes-route.yaml <<'YAML'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: notes
spec:
  parentRefs:
    - name: public
  hostnames:
    - notes.example.test
  rules:
    - backendRefs:
        - name: notes
          port: 80
YAML
if kubeconform -strict -summary -kubernetes-version 1.37.3 -cache ~/.cache/kubeconform crds/notes-route.yaml; then
  echo "expected a missing schema error"; false
fi

The error says could not find schema for HTTPRoute. You could add -ignore-missing-schemas, but then every custom resource goes unchecked. Point kubeconform at the community CRDs catalog instead, which publishes JSON schemas for hundreds of popular CRDs, from cert-manager to the Gateway API. Pass -schema-location twice: default keeps the Kubernetes schemas, and the template tells kubeconform how to build a catalog URL from each object's group, kind and version:

Bash
cd ~/manifest-check-demo
CATALOG='https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json'
kubeconform -strict -summary -kubernetes-version 1.37.3 -cache ~/.cache/kubeconform \
  -schema-location default -schema-location "$CATALOG" crds/notes-route.yaml
if kubeconform -strict -summary -kubernetes-version 1.37.3 -cache ~/.cache/kubeconform \
  -schema-location default -schema-location "$CATALOG" <<'YAML'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: broken
spec:
  rules:
    - backendRefs:
        - name: notes
          port: eighty
YAML
then
  echo "the bad port was not caught"; false
fi

The catalog follows the latest release of each project. If your cluster runs an older version of a CRD, or one of your own, generate schemas from the CRD itself with the openapi2jsonschema.py script in the kubeconform repository and add that folder as another -schema-location.

Check it worked

With the catalog, the route reports Valid: 1. The broken route is Invalid: 1, with an error about port expecting an integer.

Step 6 · Check generated manifests and know when to ask the cluster

kubectl create ... --dry-run=client -o yaml writes a manifest for you without contacting any cluster. It is the quickest way to get a correct skeleton for a ConfigMap or CronJob, and the output deserves the same checks:

Bash
mkdir -p ~/manifest-check-demo/generated
cd ~/manifest-check-demo
kubectl create configmap notes-settings --from-literal=LOG_LEVEL=info --dry-run=client -o yaml > generated/notes-settings.yaml
kubectl create cronjob notes-cleanup --image=registry.example.test/notes:1.4.2 --schedule="0 3 * * *" \
  --dry-run=client -o yaml -- /app/notes cleanup > generated/notes-cleanup.yaml
kubeconform -strict -summary -kubernetes-version 1.37.3 -cache ~/.cache/kubeconform generated

The generated files contain empty fields such as status: {} and creationTimestamp: null. They are harmless, but trim them and add requests, limits and a security context before you commit the files; kube-linter flags the CronJob until you do.

Everything so far is offline, and that is its limit. The schemas know the shape of an object, not your cluster. They cannot know that a namespace is missing, that an admission policy forbids latest tags, that a quota is full, or that you are trying to change a Deployment's selector, which cannot be changed after creation. When you have a cluster, --dry-run=server sends the objects to the API server, which runs its own validation and the admission webhooks and policies, then stores nothing:

Bash
kubectl apply --dry-run=server -f rendered/prod.yaml
kubectl diff -f rendered/prod.yaml

kubectl diff goes one step further and shows what would change against what is running. Use the offline checks on every commit and the server checks just before you apply, against the real target.

Check it worked

kubeconform reports 2 resources found in 2 files - Valid: 2, and generated/notes-cleanup.yaml contains schedule: 0 3 * * * and the /app/notes cleanup command.

Step 7 · Run every check from one script and in CI

Collect the checks into one script, so that your laptop and CI run exactly the same commands. It stops at the first failure:

Bash
cd ~/manifest-check-demo
cat > check-manifests.sh <<'SH'
#!/usr/bin/env bash
# Renders and checks every manifest in this folder. Exits non-zero on the first problem.
set -euo pipefail
cd "$(dirname "$0")"
K8S_VERSION=1.37.3
CACHE="${HOME}/.cache/kubeconform"
CATALOG='https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json'
mkdir -p "$CACHE" rendered

kubectl kustomize overlays/prod > rendered/prod.yaml
helm lint chart/notes
helm template notes chart/notes > rendered/helm.yaml

kubeconform -strict -summary -kubernetes-version "$K8S_VERSION" -cache "$CACHE" \
  -schema-location default -schema-location "$CATALOG" \
  base/notes.yaml rendered crds generated

kube-linter lint --config .kube-linter.yaml base/notes.yaml rendered
echo "All manifest checks passed"
SH
chmod +x check-manifests.sh
./check-manifests.sh

The script passes base/notes.yaml by name rather than the whole base folder, because kustomization.yaml is not a Kubernetes object and kubeconform would report it as a missing schema. kube-linter checks the rendered files and the base, not generated/, until you finish the CronJob.

Now the GitHub Actions job. Put the contents of manifest-check-demo (not the folder itself) at the root of a repository, so install-tools.sh and check-manifests.sh sit next to .github/, and save this as .github/workflows/manifests.yaml. Commit both scripts with their execute bit set; if your system lost it, run git add --chmod=+x install-tools.sh check-manifests.sh. The job installs the pinned tools with the same script on every run (about 150 MB each time), caches only the schemas between runs, and runs the checks on every pull request and every push to main:

YAML
name: manifests

on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/cache@v6
        with:
          path: ~/.cache/kubeconform
          key: kubeconform-schemas-${{ hashFiles('check-manifests.sh') }}
      - name: Install pinned tools
        run: ./install-tools.sh
      - name: Check manifests
        run: ./check-manifests.sh

If your repository is new to Actions, /tutorials/github-actions-first-workflow covers pushing a workflow and reading its logs. Make the validate job a required status check on main, so a pull request with an invalid manifest cannot be merged.

Check it worked

The script prints a kubeconform summary of 8 resources found in 6 files - Valid: 8, Invalid: 0, Errors: 0, Skipped: 0, then No lint errors found! and All manifest checks passed. To see it fail, put the replica: typo back in base/notes.yaml, run ./check-manifests.sh again and confirm it stops with the same error as in Step 2, then fix it. When you are finished with the demo, remove it with rm -rf ~/manifest-check-demo; the tools stay in /usr/local/bin.

Next steps

  • Package a real app as a chart, then point this script at its output: /tutorials/package-an-app-as-a-helm-chart.
  • Lay out base and environment overlays properly, with every overlay checked by kubeconform: /tutorials/lay-out-the-snip-manifests-with-kustomize-overlays.
  • Choose sensible numbers for the requests and limits kube-linter asks for: /tutorials/set-cpu-and-memory-requests-and-limits.
  • Make the image itself run as a non-root user, so runAsNonRoot holds at runtime: /tutorials/run-containers-as-a-non-root-user.

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.