Skip to content

Commit 253135d

Browse files
committed
Updated anti-affinity YAML
1 parent 95baa12 commit 253135d

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

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

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -186,33 +186,37 @@ You can use the `nodeSelector` field in your pod specification to specify the no
186186
The following example pod definition file shows how to use pod anti-affinity to ensure that pods are spread across nodes:
187187

188188
```yaml
189-
apiVersion: v1
190-
kind: Pod
189+
apiVersion: apps/v1
190+
kind: Deployment
191191
metadata:
192-
name: with-node-affinity
192+
name: multi-zone-deployment
193+
labels:
194+
app: myapp
193195
spec:
194-
affinity:
195-
nodeAffinity:
196-
requiredDuringSchedulingIgnoredDuringExecution:
197-
nodeSelectorTerms:
198-
- matchExpressions:
199-
- key: topology.kubernetes.io/zone
200-
operator: In
201-
values:
202-
- 0 # Azure Availability Zone 0
203-
- 1 # Azure Availability Zone 1
204-
- 2 # Azure Availability Zone 2
205-
preferredDuringSchedulingIgnoredDuringExecution:
206-
- weight: 1
207-
preference:
208-
matchExpressions:
209-
- key: another-node-label-key
210-
operator: In
211-
values:
212-
- another-node-label-value
213-
containers:
214-
- name: with-node-affinity
215-
image: registry.k8s.io/pause:2.0
196+
replicas: 3
197+
selector:
198+
matchLabels:
199+
app: myapp
200+
template:
201+
metadata:
202+
labels:
203+
app: myapp
204+
spec:
205+
containers:
206+
- name: myapp-container
207+
image: nginx
208+
ports:
209+
- containerPort: 80
210+
affinity:
211+
podAntiAffinity:
212+
requiredDuringSchedulingIgnoredDuringExecution:
213+
- labelSelector:
214+
matchExpressions:
215+
- key: app
216+
operator: In
217+
values:
218+
- myapp
219+
topologyKey: topology.kubernetes.io/zone
216220
```
217221

218222
For more information, see [Affinity and anti-affinity in Kubernetes](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity).

0 commit comments

Comments
 (0)