Comprehensive Kubernetes toolkit for YAML generation, validation, and cluster debugging
94
94%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Advisory
Suggest reviewing before use
Mental Model: Validation is a layered funnel—syntax → schema → cluster constraints → runtime behavior. Each layer catches different classes of errors.
Decision Framework:
When to use this skill:
Validation philosophy: Report all issues, prioritize by severity, suggest fixes but never apply them automatically.
This skill provides a comprehensive validation workflow for Kubernetes YAML resources, combining syntax linting, schema validation, cluster dry-run testing, and intelligent CRD documentation lookup. Validate any Kubernetes manifest with confidence before applying it to the cluster.
IMPORTANT — REPORT-ONLY: Do NOT modify files, use the Edit tool, or offer to apply fixes. Generate a comprehensive validation report with suggested fixes shown as before/after code blocks, then let the user decide what to do next.
Follow this sequential validation workflow. Each stage catches different types of issues:
Before running any validation tools, check the file complexity:
--- document separators or parsing the filereferences/validation_workflow.md:
Read references/validation_workflow.mdbash scripts/setup_tools.shRequired tools: yamllint, kubeconform, kubectl (optional). If tools are missing, display installation instructions from script output and document missing tools in the validation report.
yamllint -c assets/.yamllint <file.yaml>Report all syntax issues with file:line references. Show suggested before/after code blocks. Continue to the next stage to collect all issues before reporting.
bash scripts/detect_crd_wrapper.sh <file.yaml>The wrapper script automatically handles Python dependencies via a temporary virtual environment if PyYAML is not available.
Resilient Parsing: The script parses valid documents and reports errors for invalid ones — continuing processing rather than aborting. This matches kubeconform's behavior of validating 2/3 resources when 1/3 has syntax errors.
Script outputs JSON with resource information and parse status:
{
"resources": [
{
"kind": "Certificate",
"apiVersion": "cert-manager.io/v1",
"group": "cert-manager.io",
"version": "v1",
"isCRD": true,
"name": "example-cert"
}
],
"parseErrors": [
{
"document": 1,
"start_line": 2,
"error_line": 6,
"error": "mapping values are not allowed in this context"
}
],
"summary": {
"totalDocuments": 3,
"parsedSuccessfully": 2,
"parseErrors": 1,
"crdsDetected": 1
}
}For each detected CRD:
Query library documentation:
tessl_query_library_docs: query: "<project> <kind> <version> spec fields"
Example: "cert-manager Certificate v1 spec fields"
Example: "istio VirtualService v1beta1 specification"Fallback to WebSearch if documentation is insufficient:
"<kind>" "<group>" kubernetes CRD "<version>" documentation specExtract required spec fields, field types, validation rules, and version-specific changes.
Secondary CRD Detection: If detect_crd_wrapper.sh fails (e.g., all documents have syntax errors) but kubeconform validates a CRD resource, parse kubeconform output to identify those CRDs and perform documentation lookups.
kubeconform \
-schema-location default \
-schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json' \
-strict \
-ignore-missing-schemas \
-summary \
-verbose \
<file.yaml>For CRDs where kubeconform reports "no schema found", use the documentation from Stage 3 to manually validate spec fields.
Try server-side dry-run first:
kubectl apply --dry-run=server -f <file.yaml>Fallback logic:
--dry-run=client and document "Limited validation (no cluster access)"For updates:
kubectl diff -f <file.yaml>Constraint: Present the report and let the user take action — do NOT use the Edit tool or prompt the user to apply fixes.
Report structure:
Example issue format:
**Issue 1: deployment.yaml:21 - Wrong field type (Error) [Simple]**
Current:
```yaml
- containerPort: "80"Suggested Fix:
- containerPort: 80## Best Practices Reference
Load when schema validation fails with type errors, reports missing required fields, or dry-run fails with validation errors:Read references/k8s_best_practices.md
## Detailed Validation Workflow Reference
Load when the file contains 3+ resources, or validation produces unfamiliar errors spanning multiple stages:Read references/validation_workflow.md
## Working with Multiple Resources
When a YAML file contains multiple resources (separated by `---`):
1. Validate the entire file first with yamllint and kubeconform
2. Identify which resource has issues by checking line numbers
3. For dry-run, the file is tested as a unit
4. Track issues per-resource in the report
**Partial parsing:** Tools parse valid documents and continue when some documents have syntax errors:
| Document | Resource | Parsing | Validation |
|----------|----------|---------|------------|
| 1 | Deployment | ❌ Syntax error (line 6) | Skipped |
| 2 | Service | ✅ Parsed | ✅ Valid |
| 3 | Certificate | ✅ Parsed | ✅ Valid |
**Always use file-absolute line numbers** (relative to the start of the entire file) — this matches what yamllint, kubeconform, and kubectl report, and lets users navigate directly to errors in their editor.
## Common Anti-Patterns
### NEVER: Skip Validation Because "It Looks Fine"
**BAD**:
```bash
# Directly applying without validation
kubectl apply -f deployment.yamlGOOD:
# Validate first, apply only after clean report
yamllint deployment.yaml
kubeconform deployment.yaml
kubectl apply --dry-run=server -f deployment.yaml
# Then apply
kubectl apply -f deployment.yamlBAD:
# Fix syntax error on line 10, re-run, fix next error, repeat...
# This takes 10x longer than collecting all issues upfrontGOOD:
# Run full validation workflow once
# Fix all errors in one pass using the comprehensive report
# Re-validate to confirm cleanBAD:
# "It's just a warning, ship it"
apiVersion: extensions/v1beta1 # Deprecated API version
kind: DeploymentGOOD:
# Warnings indicate future breakage—fix them now
apiVersion: apps/v1
kind: DeploymentBAD:
# Using default kubeconform schemas (may not match cluster version)
kubeconform deployment.yamlGOOD:
# Always validate against target cluster version
kubectl version # Check cluster version
kubeconform -kubernetes-version 1.28.0 deployment.yaml
# Or use server-side dry-run (inherently correct)
kubectl apply --dry-run=server -f deployment.yamlBAD:
kubectl apply --dry-run=client -f deployment.yaml # Misses cluster-specific issuesGOOD:
# Use server-side dry-run to catch admission webhooks, RBAC, quotas
kubectl apply --dry-run=server -f deployment.yamlCRD order matters (e.g., namespace before resources in that namespace):
# Validate the full file, not individual resources
kubectl apply --dry-run=server -f all-resources.yaml# Verify CRD version matches what's installed in cluster
kubectl get crd <crd-name> -o jsonpath='{.spec.versions[*].name}'scripts/setup_tools.sh to check availability and get installation instructionskubectl get crd <crd-name>.group -o yaml
kubectl explain <kind>extensions/v1beta1 → apps/v1)kubectl api-versions to list available API versionsAfter the user applies fixes:
kubectl apply -f <file.yaml> --namespace=dev
kubectl get <resource> -n dev -w # Watch for successful creationdetect_crd_wrapper.sh — Wrapper that manages Python dependencies (auto-creates venv if PyYAML unavailable) and calls detect_crd.py.
Usage: bash scripts/detect_crd_wrapper.sh <file.yaml>
detect_crd.py — Parses YAML files to identify CRDs; extracts kind, apiVersion, group, version; outputs JSON.
Usage: python3 scripts/detect_crd.py <file.yaml>
setup_tools.sh — Checks for required validation tools, reports versions, provides installation instructions.
Usage: bash scripts/setup_tools.sh
k8s_best_practices.md — Kubernetes YAML best practices: metadata, labels, resource limits, security context, common validation issues.
validation_workflow.md — Detailed workflow, command options, error handling strategies, complete workflow diagram.
.yamllint — Pre-configured yamllint rules following Kubernetes conventions (2-space indentation, line length, etc.).
Usage: yamllint -c assets/.yamllint <file.yaml>