# Kubernetes Manifest Validator API

> Validate Kubernetes YAML against the official schemas of 8 recent versions, flag removed APIs and lint resources, probes, image tags and security.

- Endpoint: `GET | POST https://apibox.io.vn/v1/k8s-validate`
- Category: Developer utilities
- HTML docs: https://apibox.io.vn/docs/k8s-validate/ (Vietnamese: https://apibox.io.vn/vi/docs/k8s-validate/)
- Online tool: https://apibox.io.vn/tools/k8s-validate/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

Send one or more YAML (or JSON) documents as `yaml`, a file or a raw body; `List` kinds are expanded. Each object is validated against the OpenAPI schema of the chosen Kubernetes `version` (the last 8 minor releases, latest patch, default the newest; `/v1/k8s-validate/versions` lists them) with field types, required fields, enums and — in `strict` mode (default) — unknown fields such as a misspelled `imagePullPolice`. `null` values (e.g. `creationTimestamp: null` from kubectl) are ignored.

An apiVersion / kind not served by that version is reported as `not_served` with the release that removed it and the replacement (for example batch/v1beta1 CronJob → batch/v1 since 1.25), or the versions that serve it. Unknown kinds (custom resources) are skipped.

`lint` (default on) checks workloads (Deployment, StatefulSet, DaemonSet, Job, CronJob, Pod…): image without tag or `:latest`, missing CPU / memory requests and memory limit, missing readiness / liveness probes, privileged containers, privilege escalation, running as root, hostNetwork / hostPID / hostIPC, hostPath volumes, dangerous capabilities, literal secrets in env, single replica, NodePort services. Schemas come from the Kubernetes OpenAPI spec (Apache-2.0) and are refreshed weekly.

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `yaml` | body | string | yes |  | One or more YAML / JSON documents (or a file / raw body). |
| `version` | body|query | string | no |  | Kubernetes minor version, e.g. `1.35` (default: newest bundled). |
| `strict` | body|query | boolean | no | `true` | Reject fields not in the schema. |
| `lint` | body|query | boolean | no | `true` | Run best-practice checks. |

## Example request

```bash
curl -X POST "https://apibox.io.vn/v1/k8s-validate" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"yaml":"apiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: web\nspec:\n  replicas: 2\n  selector: {matchLabels: {app: web}}\n  template:\n    metadata: {labels: {app: web}}\n    spec:\n      containers:\n      - name: web\n        image: nginx:latest\n        ports: [{containerPort: \"80\"}]\n---\napiVersion: batch/v1beta1\nkind: CronJob\nmetadata: {name: report}\n","version":"1.37"}'
```

## Example response

```json
{
  "kubernetes_version": "1.37",
  "release": "v1.37.2",
  "strict": true,
  "valid": false,
  "summary": {
    "objects": 2,
    "valid": 0,
    "invalid": 1,
    "not_served": 1,
    "skipped": 0,
    "lint_errors": 0,
    "lint_warnings": 6
  },
  "results": [
    {
      "document": 0,
      "kind": "Deployment",
      "api_version": "apps/v1",
      "name": "web",
      "status": "invalid",
      "errors": [
        {
          "path": "spec.template.spec.containers.0.ports.0.containerPort",
          "message": "type \"string\" is invalid. Expected \"integer\"."
        }
      ],
      "lint": [
        {
          "rule": "image-latest",
          "severity": "warning",
          "message": "container \"web\": image tag :latest is not reproducible; pin a version or digest",
          "path": "spec.template.spec.containers[0].image"
        },
        {
          "rule": "resources-requests",
          "severity": "warning",
          "message": "container \"web\" has no CPU / memory requests (scheduling and QoS are guessed)",
          "path": "spec.template.spec.containers[0].resources.requests"
        },
        "…"
      ]
    },
    {
      "document": 1,
      "kind": "CronJob",
      "api_version": "batch/v1beta1",
      "name": "report",
      "status": "not_served",
      "errors": [
        {
          "path": "apiVersion",
          "message": "batch/v1beta1/CronJob is not served by Kubernetes 1.37 (removed in 1.25; use batch/v1)"
        }
      ],
      "available_in": [],
      "use_api_version": [
        "batch/v1"
      ]
    }
  ]
}
```

## Use cases

- Check manifests or Helm template output before kubectl apply
- Find APIs that break when upgrading a cluster to a new Kubernetes version
- Review security basics (root, privileged, hostPath) in pull requests
- Validate YAML generated by scripts or no-code tools

## FAQ

### Does it support CRDs?

Custom resources are reported as skipped; only built-in Kubernetes kinds are validated.

### Can I validate Helm charts?

Render them first (helm template) and send the output; templates with {{ }} are not valid YAML.

### Is my manifest stored?

No. It is validated in memory; secrets in it are never logged or kept.
