notes on AFFINITY AND NODE WEIGHT

Get info about Affinity and node weight 

There are four ways to assigning pods to nodes…...



 1.node Selector field matching against node labels

 2.Affinity and anti-affinity node

 3.Name field Pod topology spread constraints


 In all that why we choose affinity and anti-affinity method –

 Merits

1. Affinity and anti-affinity expand the types of constraints you can define on node selector.

2. Max control over

The affinity/anti-affinity language is more expressive node selector only selects nodes with all the specified labels. Affinity/anti-affinity gives you more control over the selection logic. 

• You can constrain a Pod using labels on other Pods running on the node (or other topological domain), instead of just node labels, which allows you to define rules for which Pods can be co-located on a node.

 Types of affinity:



To use inter-pod affinity, use the affinity. pod Affinity field in the Pod spec. For inter-pod anti-affinity, use the affinity pod Ant Affinity field in the Pod spec. 

➢ For example, you could use requiredDuringSchedulingIgnoredDuringExecution affinity to tell the scheduler to co-locate Pods of two services in the same cloud provider zone because they communicate with each other a lot. Similarly, you could use preferredDuringSchedulingIgnoredDuringExecution anti-affinity to spread Pods from a service across multiple cloud provider zones. 

➢ You can specify node affinities using the. spec. affinity. node Affinity field in your Pod spec. ➢ In the preceding typesIgnoredDuingExecution means that if the node labels change after Kubernetes schedules the Pod, the Pod continues to run.

 ➢ For example, consider the following pod yaml file or spec........ 


apiVersion: v1

kind: Pod

metadata:

  name: with-node-affinity

spec:

  affinity:

    nodeAffinity:

      requiredDuringSchedulingIgnoredDuringExecution:

        nodeSelectorTerms:

        - matchExpressions:

          - key: topology.kubernetes.io/zone

            operator: In

            values:

            - antarctica-east1

            - antarctica-west1

      preferredDuringSchedulingIgnoredDuringExecution:

      - weight: 1

        preference:

          matchExpressions:

          - key: another-node-label-key

            operator: In

            values:

            - another-node-label-value

  containers:

  - name: with-node-affinity

    image: registry.k8s.io/pause:2.0

 

 


. • The node preferably has a label with the key another-node-label-key and the value another-node-label-value.

 ➢ Node affinity weight-

 • Always between 1 to 100/instance launched by developer of Kubernetes cluster during affinity type PreffeerredDuingExecution.

 • When the scheduler finds nodes that meet all the other scheduling requirements of the Pod, the scheduler iterates through every preferred rule that the node satisfies and adds the value of the weight for that expression to a sum.

 First get a cluster whatever want like on AWS nodes machines or other options. And then start applying any of this or above mention method to assign a pod. before that you have to knowledge of nodename and namespace so you can understand this easily……

Comments

Popular Posts