Skip to main content

How to achieve Node Affinity (Hard) in K8S 1/2

 If you are running with a multi-mode cluster and when you want to place your pods on specific nodes then node affinity is the best option. to achieve the node affinity you have to mention in the manifest specification.

There are two types of affinity: hard and soft. 
  • requiredDuringSchedulingIgnoredDuringExecution ( Hard)
  • preferredDuringSchedulingIgnoredDuringExecution (soft)

when we use required that means hard affinity and preferred means soft affinity. In simple way when you want to place pod on specific node then you can use the required option and when you have two nodes then you can mention the weight to place the pods.

Request: you need place a nginx pod to k8s-n2 with 2 replicas.

Hard Affinity -
    I have 3 node cluster as follows;
         

my manifest file as follows.
In my manifest file if you see closely the match expression has set to key and value pairs.
the key is "servers" and value is "qrst-app", this means if the label will match then the pod will deploy on the node.

The label is already set to my node2 for "qrst-app" application snip.
       $ k8s-ms$ kubectl get no k8s-n2 --show-labels
        NAME     STATUS   ROLES    AGE   VERSION   LABELS
        k8s-n2   Ready    <none>   11d   v1.18.3   beta.kubernetes.io/arch=amd64, servers=qrst-app

Now lets create the pod: 
    kubectl create -f hardaffinitypods.yaml
    pod/ha-pods created

query the details of the newly created pod.

We will see the soft node affinity in the next section: How to achieve Node Affinity (Soft) in K8S  2/2

Comments

Popular posts from this blog

01 Azure DevOps in Hindi

Hello Folks, This is my first video about Azure DevOps in Hindi.

Printing - NATO phonetic alphabet #python3

  Hi Foks, This code illustrates how to print the NATO phonetic alphabet in Python3. prompt_response = str ( input ( "Enter your name?" )) dict = { 'A' : 'Alpha' , 'B' : 'Bravo' , 'C' : 'Charlie' , 'D' : 'Delta' , 'E' : 'Echo' , 'F' : 'Foxtrot' , 'G' : 'Golf' , "H" : "Hotel" , 'I' : 'India' , 'J' : 'Juliet' , 'K' : 'Kilo' , 'L' : 'Lima' , 'M' : 'Mike' , 'N' : 'November' , 'O' : 'Oscar' , 'P' : 'Papa' , 'Q' : 'Quebec' , 'R' : 'Romeo' , 'S' : 'Sierra' , 'T' : 'Tango' , 'U' : 'Uniform' , 'V' : 'Victor' , 'W' : 'Whiskey' , 'X' : 'Xray' , 'Y' : 'Yankee' , 'Z' : '...

How I Fixed an Azure SQL Server Error: Retrieving Long Term Retention Policies for Database Using Terraform

During my recent project, I encountered a deployment issue while configuring Azure SQL Server and Long Term Retention (LTR) Policies using Terraform . The error occurred when attempting to retrieve the LTR policies, and the root cause was twofold: Incorrect Dependency References : The problem stemmed from an incorrect reference within the SQL Server identity block, which led to Terraform not properly managing dependencies. Specifically, it failed to establish the necessary order for operations. Race Condition with Key Vault Encryption : In addition, there was a race condition with the Key Vault encryption key , where the SQL Server identity was trying to assign access policies before the encryption key was fully created and available. These challenges resulted in deployment failures, manifesting in errors such as "retrieving Long Term Retention Policies" and improper assignment of access policies to the SQL Server identity. How I Fixed It To resolve the issue: I ensured tha...