Source
Book Review
The chapter material is based on a detailed analysis of the book on the blog
Kubernetes Patterns, 2nd Edition
Authors: Bilgin Ibryam, Roland Huß
Publisher: O'Reilly Media, 2019 (2nd Edition 2023)
Length: 390 pages
Catalog of patterns for K8s: fundamental, behavioral, structural and configuration patterns from Bilgin Ibryam.
Original
TranslatedDocumentaries
Related book
Cloud Native
Context of cloud-native development: containers, serverless, data management.
Pattern categories
Foundational Patterns
Basic principles: how to containerize applications, manage lifecycles and define health checks.
Behavioral Patterns
How applications interact with the platform: batch jobs, scheduled tasks, stateful workloads.
Structural Patterns
Organization of containers in Pod: sidecar, ambassador, adapter and other multi-container patterns.
Configuration Patterns
Configuration management: ConfigMaps, Secrets, immutable configuration, configuration templates.
Podcast
Code of Architecture
Discussion of Kubernetes Patterns in the Code of Architecture club podcast
Foundational Patterns
Health Probe
Mechanisms for determining application state:
Liveness Probe
Is the process alive? Restart in case of failure.
Readiness Probe
Are you ready to receive traffic?
Startup Probe
For slow-starting applications.
Predictable Demands
Declaration of resource requirements for proper scheduling:
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"Managed Lifecycle
Graceful shutdown via preStop hooks and SIGTERM handling. PostStart hooks for initialization. Correct signal processing is critical for zero-downtime deployments.
Podcast
Code of Architecture
Continued discussion of Kubernetes Patterns in the podcast
Behavioral Patterns
Related book
Site Reliability Engineering
SRE practices for managing workloads in production.
Batch Job
Kubernetes Job for run-to-completion tasks. Parallel execution, retry policies, backoff limits. Ideal for data processing, migrations, reports.
Periodic Job (CronJob)
Scheduled cron tasks. Concurrency policies: Allow, Forbid, Replace. History of successful and unsuccessful jobs.
Stateful Service
StatefulSet for stateful applications: databases, message queues. Stable network identities, ordered deployment, persistent storage per pod.
Service Discovery
Kubernetes Services: ClusterIP, NodePort, LoadBalancer. DNS-based discovery (service.namespace.svc.cluster.local). Headless services for StatefulSets.
Podcast
Code of Architecture
Part three of the Kubernetes Patterns podcast discussion
Structural Patterns (Multi-Container)
Sidecar
An additional container extends the functionality of the main one without changing its code.
Ambassador
Proxy to simplify access to external services. Hides connection complexity.
Adapter
Converts the application's output to a standard format. Useful for legacy systems.
Init Container
Executes before the main container. Preparing the environment, waiting for dependencies.
Deep Dive
Designing Distributed Systems
Brendan Burns examines configuration and operational patterns in detail.
Configuration Patterns
EnvVar Configuration
The simplest way is environment variables. Suitable for a small number of parameters. You can use valueFrom to reference ConfigMaps/Secrets.
Configuration Resource (ConfigMap)
Storing the configuration separately from the image. Mount as files or env vars.
Immutable Configuration
Configuration as part of an immutable image. Guarantees consistency between environments. Requires reassembly for changes - trade-off between safety and flexibility.
Secret Management
Kubernetes Secrets for sensitive data. Base64 encoding (not encryption!). Integration with external secret managers: Vault, AWS Secrets Manager, Azure Key Vault.
Podcast
Code of Architecture
Advanced Patterns Podcast Discussion
Advanced Patterns
Controller
Reconciliation loop: observe → diff → act. The basis of all Kubernetes controllers. Custom controllers to automate operations.
Operator
Controller + CRD = domain-specific automation. Codification of operational knowledge. Examples: Prometheus Operator, Strimzi.
Elastic Scale
HorizontalPodAutoscaler by CPU, memory or custom metrics. VerticalPodAutoscaler for right-sizing. KEDA for event-driven scaling.
Self Awareness
Downward API for accessing pod metadata. Pod name, namespace, labels, annotations are available to the application.
Related book
Building Microservices
Patterns of decomposition and communication of interview services.
Application at System Design interview
Useful Concepts
- Health probes for zero-downtime deployments
- Sidecar pattern for cross-cutting concerns
- StatefulSet for stateful workloads
- Init containers for dependencies
- Resource requests/limits for capacity
- HPA for auto-scaling
Questions where it will be useful
- “How to deploy a service without downtime?”
- “How to scale a stateful service?”
- “How to organize a service mesh?”
- “How to add logging/tracing?”
- "How to manage secrets?"
