YAML for Infrastructure
YAML has become the standard for declaring infrastructure. Here are real-world examples across popular tools.
Docker Compose
yaml
version: "3.9"
services:
app:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgres://user:pass@db:5432/myapp
- REDIS_URL=redis://cache:6379
depends_on:
- db
- cache
restart: unless-stopped
db:
image: postgres:16-alpine
volumes:
- pgdata:/var/lib/postgresql/data
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: myapp
cache:
image: redis:7-alpine
command: redis-server --maxmemory 256mb --maxmemory-policy allkeys-lru
volumes:
pgdata:
Kubernetes Deployment
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: monitoring-agent
labels:
app: xitoring-agent
spec:
replicas: 3
selector:
matchLabels:
app: xitoring-agent
template:
metadata:
labels:
app: xitoring-agent
spec:
containers:
- name: agent
image: xitoring/agent:latest
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
env:
- name: API_KEY
valueFrom:
secretKeyRef:
name: xitoring-secrets
key: api-key
GitHub Actions CI/CD
yaml
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: |
npm ci
npm test
- name: Build and push Docker image
run: |
docker build -t myapp:latest .
docker push myapp:latest
- name: Notify monitoring
run: |
curl -X POST https://api.xitoring.com/deployments
Key Takeaways
YAML configs make your infrastructure reproducible, version-controlled, and auditable. Pair them with monitoring to catch misconfigurations before they hit production.
