Skip to content

Commit 93d5c87

Browse files
Merge pull request #272987 from schaffererin/userstory247939
Replaced pod anti-affinity with pod topology spread constraints
2 parents 13a75c9 + 648e1e4 commit 93d5c87

File tree

1 file changed

+20
-46
lines changed

1 file changed

+20
-46
lines changed

articles/aks/best-practices-app-cluster-reliability.md

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ title: Deployment and cluster reliability best practices for Azure Kubernetes Se
33
titleSuffix: Azure Kubernetes Service
44
description: Learn the best practices for deployment and cluster reliability for Azure Kubernetes Service (AKS) workloads.
55
ms.topic: conceptual
6-
ms.date: 03/11/2024
6+
ms.date: 04/22/2024
77
author: schaffererin
88
ms.author: schaffererin
9-
109
---
1110

1211
# Deployment and cluster reliability best practices for Azure Kubernetes Service (AKS)
@@ -17,7 +16,7 @@ The best practices in this article are organized into the following categories:
1716

1817
| Category | Best practices |
1918
| -------- | -------------- |
20-
| [Deployment level best practices](#deployment-level-best-practices) |[Pod Disruption Budgets (PDBs)](#pod-disruption-budgets-pdbs) <br/> • [Pod CPU and memory limits](#pod-cpu-and-memory-limits) <br/> • [Pre-stop hooks](#pre-stop-hooks) <br/> • [maxUnavailable](#maxunavailable) <br/> • [Pod anti-affinity](#pod-anti-affinity) <br/> • [Readiness, liveness, and startup probes](#readiness-liveness-and-startup-probes) <br/> • [Multi-replica applications](#multi-replica-applications) |
19+
| [Deployment level best practices](#deployment-level-best-practices) |[Pod Disruption Budgets (PDBs)](#pod-disruption-budgets-pdbs) <br/> • [Pod CPU and memory limits](#pod-cpu-and-memory-limits) <br/> • [Pre-stop hooks](#pre-stop-hooks) <br/> • [maxUnavailable](#maxunavailable) <br/> • [Pod topology spread constraints](#pod-topology-spread-constraints) <br/> • [Readiness, liveness, and startup probes](#readiness-liveness-and-startup-probes) <br/> • [Multi-replica applications](#multi-replica-applications) |
2120
| [Cluster and node pool level best practices](#cluster-and-node-pool-level-best-practices) |[Availability zones](#availability-zones) <br/> • [Cluster autoscaling](#cluster-autoscaling) <br/> • [Standard Load Balancer](#standard-load-balancer) <br/> • [System node pools](#system-node-pools) <br/> • [Accelerated Networking](#accelerated-networking) <br/> • [Image versions](#image-versions) <br/> • [Azure CNI for dynamic IP allocation](#azure-cni-for-dynamic-ip-allocation) <br/> • [v5 SKU VMs](#v5-sku-vms) <br/> • [Do *not* use B series VMs](#do-not-use-b-series-vms) <br/> • [Premium Disks](#premium-disks) <br/> • [Container Insights](#container-insights) <br/> • [Azure Policy](#azure-policy) |
2221

2322
## Deployment level best practices
@@ -178,60 +177,35 @@ spec:
178177

179178
For more information, see [Max Unavailable](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#max-unavailable).
180179

181-
### Pod anti-affinity
180+
### Pod topology spread constraints
182181

183182
> **Best practice guidance**
184183
>
185-
> Use pod anti-affinity to ensure that pods are spread across nodes for node-down scenarios.
184+
> Use pod topology spread constraints to ensure that pods are spread across different nodes or zones to improve availability and reliability.
186185

187-
You can use the `nodeSelector` field in your pod specification to specify the node labels you want the target node to have. Kubernetes only schedules the pod onto nodes that have the specified labels. Anti-affinity expands the types of constraints you can define and gives you more control over the selection logic. Anti-affinity allows you to constrain pods against labels on other pods.
186+
You can use pod topology spread constraints to control how pods are spread across your cluster based on the topology of the nodes and spread pods across different nodes or zones to improve availability and reliability.
188187

189-
The following example pod definition file shows how to use pod anti-affinity to ensure that pods are spread across nodes:
188+
The following example pod definition file shows how to use the `topologySpreadConstraints` field to spread pods across different nodes:
190189

191190
```yaml
192-
apiVersion: apps/v1
193-
kind: Deployment
191+
apiVersion: v1
192+
kind: Pod
194193
metadata:
195-
name: multi-zone-deployment
196-
labels:
197-
app: myapp
194+
name: example-pod
198195
spec:
199-
replicas: 3
200-
selector:
201-
matchLabels:
202-
app: myapp
203-
template:
204-
metadata:
205-
labels:
206-
app: myapp
207-
spec:
208-
containers:
209-
- name: myapp-container
210-
image: nginx
211-
ports:
212-
- containerPort: 80
213-
affinity:
214-
podAntiAffinity:
215-
requiredDuringSchedulingIgnoredDuringExecution:
216-
- labelSelector:
217-
matchExpressions:
218-
- key: app
219-
operator: In
220-
values:
221-
- myapp
222-
topologyKey: topology.kubernetes.io/zone
196+
# Configure a topology spread constraint
197+
topologySpreadConstraints:
198+
- maxSkew: <integer>
199+
minDomains: <integer> # optional
200+
topologyKey: <string>
201+
whenUnsatisfiable: <string>
202+
labelSelector: <object>
203+
matchLabelKeys: <list> # optional
204+
nodeAffinityPolicy: [Honor|Ignore] # optional
205+
nodeTaintsPolicy: [Honor|Ignore] # optional
223206
```
224207

225-
For more information, see [Affinity and anti-affinity in Kubernetes](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity).
226-
227-
> [!TIP]
228-
> Use pod anti-affinity across availability zones to ensure that pods are spread across availability zones for zone-down scenarios.
229-
>
230-
> You can think of availability zones as backups for your application. If one zone goes down, your application can continue to run in another zone. You use affinity and anti-affinity rules to schedule specific pods on specific nodes. For example, let's say you have a memory/CPU-intensive pod, you might want to schedule it on a larger VM SKU to give the pod the capacity it needs to run.
231-
>
232-
> When you deploy your application across multiple availability zones, you can use pod anti-affinity to ensure that pods are spread across availability zones. This practice helps ensure that your application remains available in the event of a zone-down scenario.
233-
>
234-
> For more information, see [Best practices for multiple zones](https://kubernetes.io/docs/setup/best-practices/multiple-zones/) and [Overview of availability zones for AKS clusters](./availability-zones.md#overview-of-availability-zones-for-aks-clusters).
208+
For more information, see [Pod Topology Spread Constraints](https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/).
235209

236210
### Readiness, liveness, and startup probes
237211

0 commit comments

Comments
 (0)