/devops-skills:k8s-yaml-validatorfrom devops-skills
Validates, lints, and tests Kubernetes YAML resources with syntax checking, schema validation, cluster dry-run, and CRD documentation lookup. Report-only tool that generates before/after fix suggestions.
Ships in devops-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
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: This is a REPORT-ONLY validation tool. Do NOT modify files, do NOT use Edit tool, do NOT use AskUserQuestion to offer fixes. Generate a comprehensive validation report with suggested fixes shown as before/after code blocks, then let the user decide what to do next.
Invoke this skill when:
Follow this sequential validation workflow. Each stage catches different types of issues:
IMPORTANT: Before running any validation tools, check the file complexity:
Count the number of resources in the file by counting --- document separators or parsing the file
If the file contains 3 or more resources, immediately load references/validation_workflow.md:
Read references/validation_workflow.md
This ensures you have the complete workflow context for handling complex multi-resource files.
Note the resource count for the validation report summary
This pre-check ensures proper handling of complex files from the start of validation.
Before starting validation, verify required tools are installed:
bash scripts/setup_tools.sh
Required tools:
If tools are missing, display the installation instructions from the script output and continue with available tools. Document which tools are missing in the validation report.
Validate YAML syntax and formatting using yamllint:
yamllint -c assets/.yamllint <file.yaml>
Common issues caught:
Reporting approach:
Before schema validation, detect if the YAML contains Custom Resource Definitions:
bash scripts/detect_crd_wrapper.sh <file.yaml>
The wrapper script automatically handles Python dependencies by creating a temporary virtual environment if PyYAML is not available.
Resilient Parsing: The script is resilient to syntax errors in individual documents. If a multi-document YAML file has some valid and some invalid documents, the script will:
The 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:
Try context7 MCP first (preferred):
Use mcp__context7__resolve-library-id with the CRD project name
Example: "cert-manager" for cert-manager.io CRDs
Then use mcp__context7__get-library-docs with:
- context7CompatibleLibraryID from resolve step
- topic: The CRD kind (e.g., "Certificate")
- tokens: 5000 (adjust based on need)
Fallback to WebSearch if context7 fails:
Search query pattern:
"<kind>" "<group>" kubernetes CRD "<version>" documentation spec
Example:
"Certificate" "cert-manager.io" kubernetes CRD "v1" documentation spec
Extract key information:
specSecondary CRD Detection via kubeconform: If the detect_crd_wrapper.sh script fails to detect CRDs (e.g., all documents have syntax errors), but kubeconform successfully validates a CRD resource, you should still look up documentation for that CRD. Parse the kubeconform output to identify validated CRDs and perform context7/WebSearch lookups for them.
Why this matters: CRDs have custom schemas not available in standard Kubernetes validation tools. Understanding the CRD's spec requirements prevents validation errors and ensures correct resource configuration.
Validate against Kubernetes schemas using kubeconform:
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>
Options explained:
-strict: Reject unknown fields (recommended for production - catches typos)-ignore-missing-schemas: Skip validation for CRDs without available schemas-kubernetes-version 1.30.0: Validate against specific K8s versionCommon issues caught:
For CRDs: If kubeconform reports "no schema found", this is expected. Use the documentation from Stage 3 to manually validate the spec fields.
IMPORTANT: Always try server-side dry-run first. Server-side validation catches more issues than client-side because it runs through admission controllers and webhooks.
Decision Tree:
1. Try server-side dry-run first:
kubectl apply --dry-run=server -f <file.yaml>
└─ If SUCCESS → Use results, continue to Stage 6
└─ If FAILS with connection error (e.g., "connection refused",
"unable to connect", "no configuration"):
│
├─ 2. Fall back to client-side dry-run:
│ kubectl apply --dry-run=client -f <file.yaml>
│ Document in report: "Server-side validation skipped (no cluster access)"
│
└─ If FAILS with validation error (e.g., "admission webhook denied",
"resource quota exceeded", "invalid value"):
└─ Record the error, continue to Stage 6
└─ If FAILS with parse error (e.g., "error converting YAML to JSON",
"yaml: line X: mapping values are not allowed"):
└─ Record the error, skip client-side dry-run (same error will occur)
Document in report: "Dry-run blocked by YAML syntax errors - fix syntax first"
Continue to Stage 6
Note: Parse errors from earlier stages (yamllint, kubeconform) will also cause dry-run to fail. Do NOT attempt client-side dry-run as a fallback for parse errors - it will produce the same error. Parse errors must be fixed before dry-run validation can proceed.
Server-side dry-run catches:
Client-side dry-run catches (fallback):
Document in your report which mode was used:
For updates to existing resources:
kubectl diff -f <file.yaml>
This shows what would change, helping catch unintended modifications.
After completing all validation stages, generate a comprehensive report. This is a REPORT-ONLY stage.
NEVER do any of the following:
ALWAYS do the following:
Summarize all issues found across all stages in a table format:
| Severity | Stage | Location | Issue | Suggested Fix |
|----------|-------|----------|-------|---------------|
| Error | Syntax | file.yaml:5 | Indentation error | Use 2 spaces |
| Error | Schema | file.yaml:21 | Wrong type | Change to integer |
| Warning | Best Practice | file.yaml:30 | Missing labels | Add app label |
Categorize by severity:
Show before/after code blocks for each issue:
For every issue, display explicit before/after YAML snippets showing the suggested fix:
**Issue 1: deployment.yaml:21 - Wrong field type (Error)**
Current:
```yaml
- containerPort: "80"
Suggested Fix:
- containerPort: 80
Why: containerPort must be an integer, not a string. Kubernetes will reject string values. Reference: See k8s_best_practices.md "Invalid Values" section.
Provide validation summary:
## Validation Report Summary
File: deployment.yaml
Resources Analyzed: 3 (Deployment, Service, Certificate)
| Stage | Status | Issues Found |
|-------|--------|--------------|
| YAML Syntax | ❌ Failed | 2 errors |
| CRD Detection | ✅ Passed | 1 CRD detected (Certificate) |
| Schema Validation | ❌ Failed | 1 error |
| Dry-Run | ❌ Failed | 1 error |
Total Issues: 4 errors, 2 warnings
## Detailed Findings
[List each issue with before/after code blocks as shown above]
## Next Steps
1. Fix the 4 errors listed above (deployment will fail without these)
2. Consider addressing the 2 warnings for best practices
3. Re-run validation after fixes to confirm resolution
Do NOT modify files - this is a reporting tool only
For detailed Kubernetes YAML best practices, load the reference:
Read references/k8s_best_practices.md
This reference includes:
When to load (ALWAYS load in these cases):
For in-depth workflow details and error handling strategies, load the reference:
Read references/validation_workflow.md
This reference includes:
When to load (ALWAYS load in these cases):
When a YAML file contains multiple resources (separated by ---):
When a multi-document YAML file has some valid and some invalid documents:
Expected behavior:
detect_crd.py) will parse valid documents and skip invalid onesExample scenario: A file with 3 documents where document 1 has a syntax error:
Expected output:
In your report:
| Document | Resource | Parsing | Validation |
|----------|----------|---------|------------|
| 1 | Deployment | ❌ Syntax error (line 6) | Skipped |
| 2 | Service | ✅ Parsed | ✅ Valid |
| 3 | Certificate | ✅ Parsed | ✅ Valid |
Line Number Reference Style:
This ensures users get maximum validation feedback even when some documents have issues.
scripts/setup_tools.sh to check availabilitykubectl get crd <crd-name>.group -o yaml
kubectl explain <kind>
When presenting validation results:
Be clear and concise about what was found
Explain why issues matter (e.g., "This will cause pod creation to fail")
Provide context from best practices when relevant
Group related issues (e.g., all missing label issues together)
Use file:line references for all issues
Show fix complexity - Include a complexity indicator in the issue header:
Example format in issue header:
**Issue 1: deployment.yaml:8 - Wrong indentation (Error) [Simple]**
**Issue 2: deployment.yaml:15-25 - Missing security context (Warning) [Medium]**
**Issue 3: deployment.yaml - Selector mismatch with Service (Error) [Complex]**
Always provide a comprehensive report including:
NEVER offer to apply fixes - this is strictly a reporting tool
For improved validation speed, some stages can be executed in parallel:
Can run in parallel (no dependencies):
yamllint (Stage 2) and detect_crd_wrapper.sh (Stage 3) can run simultaneouslyExample parallel execution:
# Run these in parallel (using & and wait, or parallel tool calls):
yamllint -c assets/.yamllint <file.yaml>
bash scripts/detect_crd_wrapper.sh <file.yaml>
Must run sequentially:
When to parallelize:
Always consider Kubernetes version compatibility:
extensions/v1beta1 → apps/v1)kubectl api-versions to list available API versions in the clusterThe test/ directory contains example files to exercise all validation paths. Use these to verify skill behavior.
| Test File | Purpose | Expected Behavior |
|---|---|---|
deployment-test.yaml | Valid standard K8s resource | All stages pass, no errors |
certificate-crd-test.yaml | Valid CRD resource | CRD detected, context7 lookup performed, no errors |
comprehensive-test.yaml | Multi-resource with intentional errors | Syntax error detected, partial parsing works, CRD found |
Happy Path (All Valid)
deployment-test.yamlCRD Detection Path
certificate-crd-test.yamlSyntax Error Path
comprehensive-test.yamlMulti-Resource Partial Parsing
comprehensive-test.yaml (has 3 resources, 1 with syntax error)No Cluster Access Path
Missing Tools Path
When adding test files:
<scenario>-test.yamlFor any validation, the report should include:
detect_crd_wrapper.sh
bash scripts/detect_crd_wrapper.sh <file.yaml>detect_crd.py
python3 scripts/detect_crd.py <file.yaml>setup_tools.sh
bash scripts/setup_tools.shk8s_best_practices.md
validation_workflow.md
.yamllint
yamllint -c assets/.yamllint <file.yaml>references/k8s_best_practices.md (opens in a new tab)references/validation_workflow.md (opens in a new tab)scripts/detect_crd.py (opens in a new tab)scripts/detect_crd_wrapper.sh (opens in a new tab)scripts/setup_tools.sh (opens in a new tab)test/certificate-crd-test.yaml (opens in a new tab)test/comprehensive-test.yaml (opens in a new tab)test/deployment-test.yaml (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
Generated from the plugin's indexed repository (gitjfmd/ansible-skills) — no native marketplace selected
npx claudepluginhub p/gitjfmd-devops-skills-devops-skills-plugin31 skills in this plugin
/ansible-generatorComprehensive toolkit for generating best practice Ansible playbooks, roles, tasks, and inventory files./ansible-validatorComprehensive toolkit for validating, linting, testing, and automating Ansible playbooks, roles, and collections. Use this skill when working with Ansible files (.yml, .yaml playbooks, roles, inventories), validating automation code, debugging playbook execution, performing dry-run testing with check mode, or working with custom modules and collections./azure-pipelines-generatorComprehensive toolkit for generating best practice Azure DevOps Pipelines following current standards and conventions. Use this skill when creating new Azure Pipelines, implementing CI/CD workflows, or building deployment pipelines./azure-pipelines-validatorComprehensive toolkit for validating, linting, and securing Azure DevOps Pipeline configurations./bash-script-generatorComprehensive toolkit for generating best practice bash scripts following current standards and conventions. Use this skill when creating new bash scripts, implementing shell automation, text processing workflows, or building production-ready command-line tools./bash-script-validatorComprehensive toolkit for validating, linting, and optimizing bash and shell scripts. Use this skill when working with shell scripts (.sh, .bash), validating script syntax, checking for best practices, identifying security issues, or debugging shell script problems.