Posts

Showing posts from February, 2025

K8s - Deployment and HPA replicas

Image
  We all know that replica is a critical part of a K8s deployment. Default replica is 1. Setting replicas as 3 will ensure 3 pods of that deployment is running at any given time.  Replica are internally managed by replica set which is in turn controlled by the K8s  ReplicationController   . When a pod is bad or deleted as part of replicaset, replication controller will ensure a new pod is created. Now, coming to HPA (Horizontal Pod Autoscaler) which is a dynamic scaler which works at the pod level based on the metrics configured.  When we configure we must mention min and max values. They should be greater than 1. Let's image I create a HPA with min as 5 and max as 10 under the condition of CPU utilization more than 50%. Initial deployment is set with the replica as 1. On top the deployment, I am attaching a HPA with the mentioned configuration. Under HPA, we are forcing the min replicas to 5. Hence, it autoscales the pod to 5 even though the CPU utilization is ...

K8s - Affinitiy and Anti-Affinity

Image
  Affinity refers to "Establishing a relationship based on similar characteristics". Anti-Affinity refers to "Breaking a relationship based on a similar characteristics". This affinity can be set at node level and pod level. Both node and pod affinity has two parameters: required DuringScheduling IgnoredDuringExecution : Means the scheduler should look for the node matching the  nodeAffinity condition mentioned in the pod configuration file. preferred DuringScheduling IgnoredDuringExecution:  Means the scheduler tries look for the node matching the  nodeAffinity  condition mentioned in the pod configuration file. If no node is available then the scheduler creates pod on any available nodes. What is a node affinity? Node affinity says scheduler to place a pod on a node when one or more condition matches. Node affinity is very similar to "Node Selector", but under node affinity we can mention one or more conditions. I have a node labelled as  datacenter=Chen...