I've pods with two replicas, does it make sense that k8s will reschedule both replicas in the same time? if yes is there a way to avoid it ?
I guess(according to the replies from @Henry) that I need to use https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity or
topology https://kubernetes.io/blog/2020/05/introducing-podtopologyspread/
But not sure how to configure following:
1
application with 2
replicas that for example
Replica A
runs on nodeFoo
and
Replica B
run in NodeBar
A Node can have multiple pods, and the Kubernetes control plane automatically handles scheduling the pods across the Nodes in the cluster. The control plane's automatic scheduling takes into account the available resources on each Node.
In a pre-container world, they would have run on the same physical or virtual machine. Pods are tied to the Node where they are deployed and remain there until termination (according to restart policy) or deletion. In case of a Node failure, new identical Pods will be deployed on other available Nodes.
Pods on a node can communicate with all pods on all nodes without NAT. Agents on a node (system daemons, kubelet) can communicate with all the pods on that specific node.
Number of replicas. You need at least two replicas for the application to be considered minimally available.
To configure the replicas to run on different nodes podAntiAffinity
can be used. For example in the deployment spec:
spec:
template:
metadata:
labels:
name: my-app-label
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
name: my-app-label
topologyKey: kubernetes.io/hostname
This basically means, all pods matched by the label name=my-app-label
should run on hosts where the node label kubernetes.io/hostname
is different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With