You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/aks/best-practices-app-cluster-reliability.md
+29-25Lines changed: 29 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -186,33 +186,37 @@ You can use the `nodeSelector` field in your pod specification to specify the no
186
186
The following example pod definition file shows how to use pod anti-affinity to ensure that pods are spread across nodes:
187
187
188
188
```yaml
189
-
apiVersion: v1
190
-
kind: Pod
189
+
apiVersion: apps/v1
190
+
kind: Deployment
191
191
metadata:
192
-
name: with-node-affinity
192
+
name: multi-zone-deployment
193
+
labels:
194
+
app: myapp
193
195
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
216
220
```
217
221
218
222
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