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://kube.netes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity or
topology https://kube.netes.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
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 kube.netes.io/hostname
is different.
Assuming you mean a Deployment, yes the Pod objects are created and scheduled roughly simultaneously. If you want things to be created in order, use a StatefulSet.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.