home / skills / krosebrook / source-of-truth-monorepo / docker-kubernetes-orchestrator

docker-kubernetes-orchestrator skill

/.claude-custom/skills/docker-kubernetes-orchestrator

This skill provides production-grade Docker and Kubernetes guidance to containerize apps, orchestrate microservices, and deploy scalable, reliable clusters.

npx playbooks add skill krosebrook/source-of-truth-monorepo --skill docker-kubernetes-orchestrator

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
7.1 KB
---
name: Docker & Kubernetes Orchestrator
description: Expert guidance for Docker containerization and Kubernetes orchestration. Use when containerizing applications, managing multi-container setups with Docker Compose, or deploying to Kubernetes clusters.
version: 1.0.0
allowed-tools:
  - Read
  - Write
  - Edit
  - Bash
---

# Docker & Kubernetes Orchestrator

Production-grade containerization and orchestration patterns.

## Docker Patterns

### Multi-Stage Builds

```dockerfile
# Node.js optimized build
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:18-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY package*.json ./
USER node
EXPOSE 3000
CMD ["node", "dist/index.js"]
```

```dockerfile
# Python optimized build
FROM python:3.11-slim AS builder
WORKDIR /app
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

FROM python:3.11-slim AS runner
WORKDIR /app
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY . .
USER nobody
CMD ["uvicorn", "main:app", "--host", "0.0.0.0"]
```

### Docker Compose for Microservices

```yaml
version: '3.8'

services:
  api:
    build: ./api
    ports:
      - "8000:8000"
    environment:
      DATABASE_URL: postgresql://postgres:password@db:5432/app
      REDIS_URL: redis://redis:6379
    depends_on:
      - db
      - redis
    networks:
      - backend
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 30s
      timeout: 10s
      retries: 3

  worker:
    build: ./worker
    environment:
      CELERY_BROKER_URL: redis://redis:6379/0
    depends_on:
      - redis
    networks:
      - backend
    deploy:
      replicas: 3

  frontend:
    build: ./frontend
    ports:
      - "3000:3000"
    environment:
      NEXT_PUBLIC_API_URL: http://localhost:8000
    networks:
      - frontend
      - backend

  db:
    image: postgres:15-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: password
    networks:
      - backend

  redis:
    image: redis:7-alpine
    volumes:
      - redis_data:/data
    networks:
      - backend

  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./ssl:/etc/nginx/ssl:ro
    depends_on:
      - api
      - frontend
    networks:
      - frontend

volumes:
  postgres_data:
  redis_data:

networks:
  frontend:
  backend:
```

## Kubernetes Patterns

### Deployment

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
  labels:
    app: api
spec:
  replicas: 3
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
      - name: api
        image: myregistry.com/api:latest
        ports:
        - containerPort: 8000
        env:
        - name: DATABASE_URL
          valueFrom:
            secretKeyRef:
              name: db-secret
              key: url
        resources:
          requests:
            memory: "256Mi"
            cpu: "250m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health
            port: 8000
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /ready
            port: 8000
          initialDelaySeconds: 5
          periodSeconds: 5
```

### Service & Ingress

```yaml
apiVersion: v1
kind: Service
metadata:
  name: api
spec:
  selector:
    app: api
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8000
  type: ClusterIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: api
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/rate-limit: "100"
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - api.example.com
    secretName: api-tls
  rules:
  - host: api.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: api
            port:
              number: 80
```

### ConfigMap & Secrets

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  LOG_LEVEL: "info"
  MAX_CONNECTIONS: "100"
---
apiVersion: v1
kind: Secret
metadata:
  name: db-secret
type: Opaque
stringData:
  url: postgresql://user:pass@db:5432/app
  password: secret123
```

### StatefulSet for Databases

```yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
spec:
  serviceName: postgres
  replicas: 3
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:15
        ports:
        - containerPort: 5432
        env:
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: db-secret
              key: password
        volumeMounts:
        - name: data
          mountPath: /var/lib/postgresql/data
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
          storage: 10Gi
```

### Horizontal Pod Autoscaler

```yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: 80
```

## Helm Charts

```yaml
# Chart.yaml
apiVersion: v2
name: myapp
version: 1.0.0
appVersion: "1.0"

# values.yaml
replicaCount: 3
image:
  repository: myregistry.com/api
  tag: latest
  pullPolicy: IfNotPresent

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: true
  className: nginx
  hosts:
    - host: api.example.com
      paths:
        - path: /
          pathType: Prefix

resources:
  limits:
    cpu: 500m
    memory: 512Mi
  requests:
    cpu: 250m
    memory: 256Mi

autoscaling:
  enabled: true
  minReplicas: 2
  maxReplicas: 10
  targetCPUUtilizationPercentage: 70
```

## Quick Commands

```bash
# Docker
docker build -t myapp:latest .
docker run -p 8000:8000 myapp:latest
docker compose up -d
docker compose logs -f api
docker exec -it container_name sh

# Kubernetes
kubectl apply -f deployment.yaml
kubectl get pods -w
kubectl logs -f pod-name
kubectl exec -it pod-name -- sh
kubectl port-forward svc/api 8000:80
kubectl scale deployment/api --replicas=5
kubectl rollout restart deployment/api
kubectl rollout undo deployment/api

# Helm
helm install myapp ./chart
helm upgrade myapp ./chart
helm rollback myapp 1
helm list
```

---

**When to Use:** Containerizing apps, Docker Compose orchestration, Kubernetes deployments, scaling microservices.

Overview

This skill provides expert guidance for Docker containerization and Kubernetes orchestration, delivering production-grade patterns and commands for building, deploying, and scaling services. It consolidates best practices for multi-stage builds, Docker Compose microservices, Kubernetes manifests, Helm charts, and common operational commands. The content is practical and focused on repeatable patterns you can apply immediately.

How this skill works

The skill inspects your app layout and recommends container build patterns (Node, Python) including multi-stage Dockerfiles to reduce image size and separate build/runtime concerns. It maps multi-service architectures to Docker Compose with healthchecks, networks, and volumes, and translates deployment needs into Kubernetes resources: Deployments, Services, Ingress, ConfigMaps/Secrets, StatefulSets, HPAs, and Helm values. It also provides quick command snippets for local iteration, cluster operations, and Helm lifecycle management.

When to use it

  • You need a small-to-medium microservice stack locally or in CI using Docker Compose.
  • Preparing optimized images with multi-stage Dockerfiles for production.
  • Deploying stateless services and exposing them via Kubernetes Deployments, Services, and Ingress.
  • Running stateful databases with StatefulSets and persistent volume templates.
  • Autoscaling services based on CPU/memory using Horizontal Pod Autoscaler (HPA).
  • Packaging and parameterizing deployments with Helm charts for repeatable releases.

Best practices

  • Use multi-stage builds to separate build dependencies from runtime and minimize image size.
  • Define healthchecks and readiness/liveness probes to enable safe rolling updates and proper load balancing.
  • Store secrets in Kubernetes Secrets and non-sensitive config in ConfigMaps; avoid committing credentials to code.
  • Set resource requests and limits to enable stable scheduling and effective autoscaling rules.
  • Use Helm values for environment-specific overrides and keep chart templates generic and idempotent.

Example use cases

  • Containerize a Node or Python app with multi-stage Dockerfiles and run locally for development.
  • Compose an API, worker, frontend, DB, and Redis stack with Docker Compose for full-stack integration testing.
  • Deploy the API to Kubernetes with a Deployment, ClusterIP Service, Ingress with TLS, and resource constraints for production.
  • Run PostgreSQL as a StatefulSet with persistent storage and a headless service for stable networking.
  • Configure HPA to scale your API between safe min/max replicas based on CPU and memory utilization.

FAQ

How do I choose between Docker Compose and Kubernetes?

Use Docker Compose for local development and simple multi-container stacks; choose Kubernetes for production-grade orchestration, scaling, and cluster-level features.

When should I use a StatefulSet instead of a Deployment?

Use StatefulSet for stateful services that require stable network IDs and persistent storage (databases, clustered stores); use Deployment for stateless services.