Skip to content

Latest commit

 

History

History
103 lines (91 loc) · 2.36 KB

File metadata and controls

103 lines (91 loc) · 2.36 KB

Node Affinity

In this section, we will talk about "Node Affinity" feature in kubernetes.

The primary feature of Node Affinity is to ensure that the pods are hosted on particular nodes.

  • With Node Selectors we cannot provide the advance expressions.

    apiVersion: v1
    kind: Pod
    metadata:
     name: myapp-pod
    spec:
     containers:
     - name: data-processor
       image: data-processor
     nodeSelector:
      size: Large
    

    ns-old

    apiVersion: v1
    kind: Pod
    metadata:
     name: myapp-pod
    spec:
     containers:
     - name: data-processor
       image: data-processor
     affinity:
       nodeAffinity:
         requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: size
                operator: In
                values: 
                - Large
                - Medium
    

    na

    apiVersion: v1
    kind: Pod
    metadata:
     name: myapp-pod
    spec:
     containers:
     - name: data-processor
       image: data-processor
     affinity:
       nodeAffinity:
         requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: size
                operator: NotIn
                values: 
                - Small
    

    na1

    apiVersion: v1
    kind: Pod
    metadata:
     name: myapp-pod
    spec:
     containers:
     - name: data-processor
       image: data-processor
     affinity:
       nodeAffinity:
         requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: size
                operator: Exists
    

    na2

Node Affinity Types

  • Available

    • requiredDuringSchedulingIgnoredDuringExecution
    • preferredDuringSchedulingIgnoredDuringExecution
  • Planned

    • requiredDuringSchedulingRequiredDuringExecution
    • preferredDuringSchedulingRequiredDuringExecution

    nat

Node Affinity Types States

nats

nats1

K8s Reference Docs