Last updated
YAML Diff Viewer Examples
The YAML Diff Viewer compares two YAML documents structurally, highlighting added, removed, and modified keys at every level. Below are practical examples showing how the diff works across common configuration scenarios.
Basic Key Comparison
Document A (original):
app:
name: my-service
version: "1.0.0"
port: 8080
debug: false
Document B (updated):
app:
name: my-service
version: "1.1.0"
port: 9090
debug: true
timeout: 30
Diff result:
- app.version: "1.0.0" → "1.1.0" (modified, shown in yellow)
- app.port: 8080 → 9090 (modified, shown in yellow)
- app.debug: false → true (modified, shown in yellow)
- app.timeout: (added in B, shown in green)
Kubernetes Manifest Comparison
Comparing a Deployment manifest between staging and production:
Staging:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
namespace: staging
spec:
replicas: 1
template:
spec:
containers:
- name: web
image: myapp:1.2.0
resources:
requests:
memory: "128Mi"
cpu: "250m"
Production:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
namespace: production
spec:
replicas: 3
template:
spec:
containers:
- name: web
image: myapp:1.3.0
resources:
requests:
memory: "256Mi"
cpu: "500m"
Diff highlights:
- metadata.namespace: staging → production
- spec.replicas: 1 → 3
- containers[0].image: myapp:1.2.0 → myapp:1.3.0
- resources.requests.memory: 128Mi → 256Mi
- resources.requests.cpu: 250m → 500m
Docker Compose Comparison
Original compose file:
version: "3.8"
services:
db:
image: postgres:14
environment:
POSTGRES_DB: appdb
POSTGRES_USER: admin
ports:
- "5432:5432"
Updated compose file:
version: "3.8"
services:
db:
image: postgres:15
environment:
POSTGRES_DB: appdb
POSTGRES_USER: admin
POSTGRES_PASSWORD: secret
ports:
- "5432:5432"
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:
Diff result:
- services.db.image: postgres:14 → postgres:15 (modified)
- services.db.environment.POSTGRES_PASSWORD: (added)
- services.db.volumes: (added)
- volumes: (added top-level key)
CI/CD Pipeline Comparison
Comparing GitHub Actions workflow files:
Before:
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npm test
After:
on:
push:
branches: [main, develop]
jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- run: npm ci
- run: npm test
- run: npm run build
Diff highlights:
- on.push.branches: [main] → [main, develop] (sequence item added)
- jobs.build.runs-on: ubuntu-20.04 → ubuntu-22.04
- steps[0]: actions/checkout@v2 → actions/checkout@v3
- steps[1]: npm install → npm ci
- steps[3]: npm run build (added)
Semantic vs Text Diff
These two YAML documents are semantically identical but formatted differently. A text diff would show many changes; the structural diff shows zero differences:
# Document A
server: {host: localhost, port: 3000}
# Document B
server:
host: localhost
port: 3000
Structural diff result: No differences found.
Anchor and Alias Handling
The viewer resolves anchors before comparing:
# Document A
defaults: &defaults
retries: 3
timeout: 10
service:
<<: *defaults
name: api
# Document B
service:
retries: 3
timeout: 10
name: api
Structural diff result: No differences found (anchors resolved to same values).
Common Use Cases
- Reviewing infrastructure-as-code pull requests before merging
- Comparing Kubernetes manifests across dev, staging, and production
- Auditing configuration drift between environments
- Understanding what changed between two versions of a Helm chart
- Validating that a deployment only changed the intended fields
- Documenting intentional differences between environment configs
- Debugging environment-specific issues by isolating config differences
The YAML Diff Viewer focuses on semantic meaning rather than raw text, so reformatting or reordering keys never creates false positives. Only real value changes appear in the diff output.