Kubernetes YAML is where AI drafting shines and stings simultaneously: the resource shapes are well-documented (models know them cold), but the failure modes are silent — a typoed field key is simply ignored by the API server, a missing probe deploys fine and pages you later.
Tier: Core · Workflow area: Infrastructure as Code
The saving grace: K8s has machine-readable schemas and cheap static analyzers, so a tight generate→validate→score loop catches most of it before anything touches a cluster. This is the K8s edition of the verification-chain discipline.
apiVersion graveyard).Skip AI for copy-tweak jobs where your platform already provides a golden template — use the template; that is what it is for.
kubeconform (schema validation), kube-score or polaris (best-practice scoring), helm lint + helm template for charts.Prompt with the operational envelope, not just the app.
Generate Kubernetes manifests for service "checkout" (container
registry.internal/checkout:1.8.2, port 8080, /healthz and /readyz
endpoints).
Requirements:
- K8s 1.29. Deployment (3 replicas), Service (ClusterIP), HPA
(CPU 70%, min 3 max 10), PDB (maxUnavailable 1).
- Resources: requests 200m/256Mi, limits 1000m/512Mi.
- Liveness AND readiness probes on the endpoints above, sensible
initialDelay/period for a JVM-free Go service.
- securityContext: runAsNonRoot, readOnlyRootFilesystem, drop ALL caps.
- Labels per app.kubernetes.io conventions; selector labels immutable-safe.
- No default namespace; use "payments". Nothing I did not ask for.
Gate 1 — schema validation against your real version.
kubeconform -kubernetes-version 1.29.0 -strict -summary manifests/
-strict is the point: it fails unknown fields — exactly the silent-typo class (replica:, targetport:) the API server would swallow.
Gate 2 — best-practice scoring.
kube-score score manifests/*.yaml
Treat CRITICAL findings (missing probes, no resource limits, bad PDB/replica interaction) as build-breaking. Feed findings back to the assistant verbatim; it fixes them well.
Gate 3 — policy. Your org's Kyverno/OPA policies (pb-07) against the rendered manifests:
conftest test manifests/ --policy k8s-policy/
Gate 4 — server-side dry run and disposable-cluster deploy. Static tools cannot see admission webhooks, quotas, or missing Secrets/ConfigMaps:
kubectl apply --dry-run=server -f manifests/
kind create cluster && kubectl apply -f manifests/ && kubectl rollout status deploy/checkout -n payments
For Helm: helm lint, then helm template | kubeconform -strict -, then helm install --dry-run — template rendering is where chart bugs live, so validate the rendered output, never just the templates.
Wire the loop as pre-commit/CI. kubeconform + kube-score + conftest as a pre-commit hook makes the loop free forever; AI-generated or hand-written stops mattering.
Selector labels are immutable on Deployments. If the AI regenerates manifests with "improved" labels for an existing Deployment, the apply fails — or worse, someone deletes-and-recreates in prod to "fix" it. Pin selectors in the prompt for any existing workload.
kubectl apply on real clusters — dry-run and kind only.values.schema.json alongside the chart — schema-validated values catch consumer errors and it is tedious authoring AI does well.The K8s translation of validate→plan→policy→cost:
-strict clean against the cluster's actual version.kubectl apply --dry-run=server succeeds; kind-cluster rollout completes and pods pass readiness.limits: 4Gi across 10 max replicas is a real node-pool bill; check what the HPA ceiling implies before merge.-strict schema validation catches unknown keys reliably.policy/v1beta1 PDBs, autoscaling/v2beta2). Your kubeconform version pin catches this — keep it pinned to reality.values.schema.json and docs; validate rendered output for at least two values permutations (default and prod).Manifests carry internal registry paths, service names, and namespace topology. For client clusters: the entire validation loop is OSS and runs offline — only the drafting step needs an approved endpoint. Local models (via Ollama) draft standard K8s resources acceptably well since the shapes are heavily represented in training data; keep the same gates and expect one extra fix loop. Redact registry hostnames to placeholders if using public assistants.