forked from amitopenwriteup/okd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodeaffinity.txt
More file actions
43 lines (35 loc) · 1.93 KB
/
Copy pathnodeaffinity.txt
File metadata and controls
43 lines (35 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
In Kubernetes, Node Affinity is a feature that allows you to schedule pods onto specific nodes based on node attributes or labels.
Node Affinity provides more fine-grained control over pod placement compared to Node Selector. It offers greater flexibility in
defining rules and conditions for pod scheduling.
There are two types of Node Affinity:
1. RequiredDuringSchedulingIgnoredDuringExecution: Specifies that the pod must be scheduled on a node that matches the specified affinity rules.
If no node satisfies the affinity rules, the pod remains unscheduled.
2. PreferredDuringSchedulingIgnoredDuringExecution: Specifies that the pod prefers to be scheduled on a node that matches the specified affinity rules.
However, if no such node is available, the pod can still be scheduled on other nodes.
Here's an example of using Node Affinity in a pod specification:
```yaml
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: my-image
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: app
operator: In
values:
- backend
```
In the above example, the pod has a `requiredDuringSchedulingIgnoredDuringExecution`
Node Affinity rule that specifies the pod should be scheduled on a node with the label `app=backend`.
You can define more complex Node Affinity rules using various operators such as `In`, `NotIn`, `Exists`, `DoesNotExist`, etc.
This allows you to match node labels based on different conditions or combinations.
Note that Node Affinity is just one aspect of pod scheduling in Kubernetes.
There are other scheduling techniques like Node Selector, Taints, Tolerations, and
Pod Affinity/Anti-Affinity that provide additional flexibility and control over pod placement based on various criteria.