- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设部署,replicaSet 和 pod 都是 1:1:1 映射。
deployment ==> replicaSet ==> Pod
当我们进行部署时,replicaSet 增加了
pod-template-hash
标签到 pod 。所以,这看起来足以让一个 replicaSet 检查是否有足够的 pod 正在运行。那么replicaSet
matchLabels
的意义何在?选择器?为什么是强制性的?
spec:
replicas: 2
selector:
matchLabels:
app: nginx-app
现在将 pod-template-hash 的标签值更改为其中一个 pod 的其他值(此处更改为
testing
)。现在我们立即看到另一个 pod 启动了。所以replicaSet似乎并不关心
selector.matchLabels
NAME READY STATUS RESTARTS AGE LABELS
pod/nginx-app-b8b875889-cpnnr 1/1 Running 0 53s app=nginx-app,pod-template-hash=testing
pod/nginx-app-b8b875889-jlk6m 1/1 Running 0 53s app=nginx-app,pod-template-hash=b8b875889
pod/nginx-app-b8b875889-xblqr 1/1 Running 0 11s app=nginx-app,pod-template-hash=b8b875889
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE LABELS
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 151d component=apiserver,provider=kubernetes
NAME READY UP-TO-DATE AVAILABLE AGE LABELS
deployment.apps/nginx-app 2/2 2 2 53s app=nginx-app
NAME DESIRED CURRENT READY AGE LABELS
replicaset.apps/nginx-app-b8b875889 2 2 2 53s app=nginx-app,pod-template-hash=b8b875889
最佳答案
让我总结一下。整个讨论是关于:为什么部署迫使我设置 matchLabels 选择器,即使它没有它也可以轻松生存,因为它添加了 pod-template-hash 并且仅使用它就完全没问题。
在阅读了所有评论和所有讨论后,我决定查看 kubernetes 文档。
我将允许自己引用有关副本集的 k8s 文档:How a ReplicaSet works
How a ReplicaSet works:
[...]
A ReplicaSet is linked to its Pods via the Pods'metadata.ownerReferences field, which specifies what resource thecurrent object is owned by. All Pods acquired by a ReplicaSet havetheir owning ReplicaSet's identifying information within theirownerReferences field. It's through this link that the ReplicaSetknows of the state of the Pods it is maintaining and plansaccordingly.
A ReplicaSet identifies new Pods to acquire by using its selector. Ifthere is a Pod that has no OwnerReference or the OwnerReference is nota Controller and it matches a ReplicaSet's selector, it will beimmediately acquired by said ReplicaSet
Pod Selector
The .spec.selector field is a label selector. Asdiscussed earlier these are the labels used to identify potential Podsto acquire
Non-Template Pod acquisitions
While you can create bare Pods with no problems, it is stronglyrecommended to make sure that the bare Pods do not have labels whichmatch the selector of one of your ReplicaSets. The reason for this isbecause a ReplicaSet is not limited to owning Pods specified by itstemplate-- it can acquire other Pods in the manner specified in theprevious sections.
[...]
As those Pods do not have a Controller (or any object) as their ownerreference and match the selector of the [...] ReplicaSet, they willimmediately be acquired by it.
关于kubernetes - k8s - ReplicaSet matchLabel 选择器的意义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65397373/
假设部署,replicaSet 和 pod 都是 1:1:1 映射。 deployment ==> replicaSet ==> Pod 当我们进行部署时,replicaSet 增加了 pod-tem
希望你一切顺利 拜托,我无法创建这个Deployment 我不知道为什么或可能是什么错误。 似乎有些人已经遇到过这个错误,但我从评论中不明白他们是如何解决的。 我查看了 Kubernetes 文档,但
我是一名优秀的程序员,十分优秀!