Agamya Samuel
Available for work

Kubernetes Patterns Every Developer Should Know

December 1, 20242 min read

Why Patterns Matter

Kubernetes is powerful but complex. Design patterns provide proven solutions to common problems, helping you build reliable, scalable applications on top of K8s.

1. Sidecar Pattern

Extend your main container's functionality without modifying it:

apiVersion: v1
kind: Pod
spec:
  containers:
    - name: app
      image: my-app:latest
    - name: log-collector
      image: fluentd:latest
      volumeMounts:
        - name: logs
          mountPath: /var/log/app

Common sidecar use cases:

  • Log collection (Fluentd, Filebeat)
  • Service mesh proxies (Envoy, Linkerd)
  • Monitoring agents (Prometheus exporters)

2. Ambassador Pattern

Delegate network connectivity to a proxy container:

containers:
  - name: app
    image: my-app:latest
  - name: ambassador
    image: envoyproxy/envoy:latest
    ports:
      - containerPort: 8080

The ambassador handles retries, circuit breaking, and TLS termination — your app just talks to localhost.

3. Init Containers

Run setup tasks before your main containers start:

initContainers:
  - name: db-migration
    image: my-app:latest
    command: ["./migrate", "up"]
  - name: wait-for-db
    image: busybox
    command: ["sh", "-c", "until nc -z db-service 5432; do sleep 2; done"]

4. Health Probes

Three types of probes keep your application healthy:

livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
  initialDelaySeconds: 10
  periodSeconds: 5
 
readinessProbe:
  httpGet:
    path: /ready
    port: 8080
 
startupProbe:
  httpGet:
    path: /healthz
    port: 8080
  failureThreshold: 30

5. Resource Management

Always set resource requests and limits:

resources:
  requests:
    cpu: "100m"
    memory: "128Mi"
  limits:
    cpu: "500m"
    memory: "512Mi"

Conclusion

These patterns form the foundation of production-ready Kubernetes deployments. Start with health probes and resource management, then adopt sidecar and ambassador patterns as your architecture matures.

Agamya Samuel

Agamya Samuel

Software Developer & Cloud Architect