Inter-Pod Affinity Patterns
What you'll learn: You'll discover common patterns for using inter-pod affinity to intelligently colocate related workloads for performance, efficiency, and dependency management.
Why Colocation Patterns Matter
Inter-pod affinity isn't just a scheduling feature—it's a design tool. By understanding common patterns, you can architect deployments that automatically place related Pods on the same node (or close by) to reduce latency, share resources, or meet operational requirements.
Three Essential Patterns
1. Cache with Application
Deploy cache Pods (like Redis or Memcached) alongside application Pods using preferred affinity. This minimizes network latency for cache lookups. Your app Pods express affinity toward cache Pods with a matching label, ensuring they land on the same node when possible.
Example use case: A web app that heavily relies on session storage—keeping the cache local dramatically improves response times.
2. Sidecar Colocation
While sidecars naturally share a Pod, you might need to ensure entire groups of Pods with complementary sidecars stay together. Use affinity to keep monitoring agents, log collectors, or service mesh proxies near the workloads they serve.
Example use case: A logging sidecar that processes logs from multiple related services—keeping them together reduces log shipping overhead.
3. Service Dependencies
When one service depends heavily on another (like a frontend calling a backend API frequently), use affinity to reduce cross-node communication. The dependent service expresses affinity toward the provider service's topology.
Example use case: A microservices architecture where the order service constantly queries the inventory service—colocating them reduces inter-service latency.
Choosing Required vs Preferred
Use required affinity sparingly—only when colocation is absolutely necessary. Preferred affinity gives the scheduler flexibility while still optimizing placement, preventing scheduling deadlocks when resources are constrained.
Key Takeaway: Inter-pod affinity patterns—cache colocation, sidecar grouping, and service dependency placement—let you architect deployments that automatically optimize for performance and operational efficiency.