[英]K8S pods with two replicas on different nodes
I've pods with two replicas, does it make sense that k8s will reschedule both replicas in the same time ?我有两个副本的 pod,k8s 将同时重新安排两个副本是否有意义? 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我猜(根据@Henry 的回复)我需要使用https://kube.netes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity或
topology https://kube.netes.io/blog/2020/05/introducing-podtopologyspread/拓扑https://kube.netes.io/blog/2020/05/introducing-podtopologyspread/
But not sure how to configure following:但不确定如何配置以下内容:
1
application with 2
replicas that for example 1
应用程序有2
副本,例如
Replica A
runs on nodeFoo
and Replica A
在nodeFoo
上运行,并且
Replica B
run in NodeBar
Replica B
在NodeBar
中运行
To configure the replicas to run on different nodes podAntiAffinity
can be used.要将副本配置为在不同节点上运行,可以使用
podAntiAffinity
。 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.这基本上意味着,所有与 label
name=my-app-label
匹配的 pod 应该在节点 label kube.netes.io/hostname
不同的主机上运行。
Assuming you mean a Deployment, yes the Pod objects are created and scheduled roughly simultaneously.假设您的意思是部署,是的,Pod 对象是大致同时创建和调度的。 If you want things to be created in order, use a StatefulSet.
如果您希望按顺序创建事物,请使用 StatefulSet。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.