Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 459 of 8027. Package Management and AutomationFree lesson

Validating Configurations with Schema Files

Enforce strict configuration standards by creating values.schema.json files to validate user inputs and prevent deployment errors before they occur.

In this lesson, you will learn how to enforce strict configuration standards in your Helm charts using values.schema.json files to catch errors before they ever reach your cluster.

Why Configuration Validation Matters

When sharing Helm charts across teams, it is easy for users to pass incorrect data types or missing fields in their values.yaml files. If a user provides a string where an integer is expected (e.g., replicaCount: "three" instead of 3), the deployment will fail at runtime, often causing cryptic errors deep within your template logic. A JSON schema allows you to define a contract for your configuration, ensuring that the inputs are validated against your expectations during the helm install or helm template process.

Implementing the Schema

To start, create a file named values.schema.json in the root of your chart directory. Helm automatically detects this file and uses it to validate any values provided by the user.

Here is a simple example that enforces a replicaCount to be a number between 1 and 10:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "replicaCount": {
      "type": "integer",
      "minimum": 1,
      "maximum": 10
    },
    "image": {
      "type": "string"
    }
  },
  "required": ["replicaCount"]
}

By defining this schema, if a user attempts to run helm install --set replicaCount=0 my-release ./my-chart, Helm will immediately stop and report a validation error: replicaCount must be >= 1.

The Benefit to Your Pipeline

Integrating this into your CI/CD pipeline is a massive win for reliability. By running helm lint or helm template as part of your automated testing, you shift left the validation process. You no longer have to wait for the orchestrator to struggle with invalid manifests; your configuration contract ensures that only well-formed, valid parameters are permitted, significantly reducing "deployment friction" and debugging time for your team.

Key Takeaway: By defining a values.schema.json file, you create a declarative contract for your Helm charts that automatically validates user inputs, preventing runtime deployment failures and enforcing configuration standards across your infrastructure.