mirror of
https://github.com/marcel-dempers/docker-development-youtube-series.git
synced 2025-06-06 17:01:30 +00:00
affinity updates
This commit is contained in:
parent
f925d502f4
commit
f5a6234ef4
@ -22,7 +22,7 @@ demo-worker3 Ready <none> 35s v1.28.0
|
|||||||
|
|
||||||
## Node Affinity
|
## Node Affinity
|
||||||
|
|
||||||
[Node Affinity](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity) is similar to `nodeSelector` however you can define more complex expressions
|
[Node Affinity](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity) is similar to `nodeSelector` however you can define more complex expressions. "Like my pods must run on SSD nodes or preffer SSD nodes"
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
* Node selector is a hard and fast rule meaning a pod will not be scheduled if the selection is not satisfied
|
* Node selector is a hard and fast rule meaning a pod will not be scheduled if the selection is not satisfied
|
||||||
@ -59,5 +59,34 @@ kubectl taint nodes demo-worker type=ssd:NoSchedule-
|
|||||||
kubectl taint nodes demo-worker3 type=ssd:NoSchedule-
|
kubectl taint nodes demo-worker3 type=ssd:NoSchedule-
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Pod Affinity
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
kubectl apply -f app-disk --replicas 3
|
||||||
|
kubectl apply -f web-disk --replicas 3
|
||||||
|
```
|
||||||
|
|
||||||
|
## Pod Anti-Affinity
|
||||||
|
|
||||||
|
Let's say we observe our `app-disk` application disk usage is quite intense, and we would like to prevent `app-disk` pods from running together. </br>
|
||||||
|
This is where anti-affinity comes in:
|
||||||
|
|
||||||
|
```
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- app-disk
|
||||||
|
topologyKey: "kubernetes.io/hostname"
|
||||||
|
```
|
||||||
|
|
||||||
|
After applying the above, we can roll it out:
|
||||||
|
|
||||||
|
```
|
||||||
|
kubectl apply -f node-affinity.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
@ -2,17 +2,17 @@ kind: Cluster
|
|||||||
apiVersion: kind.x-k8s.io/v1alpha4
|
apiVersion: kind.x-k8s.io/v1alpha4
|
||||||
nodes:
|
nodes:
|
||||||
- role: control-plane
|
- role: control-plane
|
||||||
- role: worker
|
- role: worker #demo-worker
|
||||||
labels:
|
labels:
|
||||||
zone: us-east
|
zone: us-east
|
||||||
type: ssd
|
type: ssd
|
||||||
- role: worker
|
- role: worker #demo-worker2
|
||||||
labels:
|
labels:
|
||||||
zone: us-west
|
zone: us-west
|
||||||
type: ssd
|
type: ssd
|
||||||
- role: worker
|
- role: worker #demo-worker3
|
||||||
labels:
|
labels:
|
||||||
zone: us-east
|
zone: us-east
|
||||||
- role: worker
|
- role: worker #demo-worker4
|
||||||
labels:
|
labels:
|
||||||
zone: us-west
|
zone: us-west
|
||||||
|
@ -19,6 +19,15 @@ spec:
|
|||||||
- name: app-disk
|
- name: app-disk
|
||||||
image: nginx:latest
|
image: nginx:latest
|
||||||
affinity:
|
affinity:
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- app-disk
|
||||||
|
topologyKey: "kubernetes.io/hostname"
|
||||||
nodeAffinity:
|
nodeAffinity:
|
||||||
requiredDuringSchedulingIgnoredDuringExecution:
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
nodeSelectorTerms:
|
nodeSelectorTerms:
|
||||||
|
@ -2,29 +2,29 @@
|
|||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: app-disk2
|
name: web-disk
|
||||||
labels:
|
labels:
|
||||||
app: app-disk2
|
app: web-disk
|
||||||
spec:
|
spec:
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: app-disk2
|
app: web-disk
|
||||||
replicas: 1
|
replicas: 1
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: app-disk2
|
app: web-disk
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: app-disk2
|
- name: web-disk
|
||||||
image: nginx:latest
|
image: nginx:latest
|
||||||
affinity:
|
affinity:
|
||||||
podAffinity:
|
podAffinity:
|
||||||
requiredDuringSchedulingIgnoredDuringExecution:
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
- labelSelector:
|
- labelSelector:
|
||||||
matchExpressions:
|
matchExpressions:
|
||||||
- key: zone
|
- key: app
|
||||||
operator: In
|
operator: In
|
||||||
values:
|
values:
|
||||||
- us-east
|
- app-disk
|
||||||
topologyKey: zone
|
topologyKey: "kubernetes.io/hostname"
|
Loading…
x
Reference in New Issue
Block a user