简体   繁体   English

k8如何知道要更新哪个吊舱?

[英]How does k8s know which pod to update?

I'm currently getting started with Kubernetes, and so far, I have a question that I could not find answered anywhere. 我目前正开始使用Kubernetes,到目前为止,我有一个问题,在任何地方都找不到答案。

Until know, I have learned what containers, pods, and replica sets are. 在不知不觉中,我已经了解了什么是容器,容器和副本集。 I basically understand the things, but one thing I did not get is: If I update a manifest of a pod (or of a replica set), and re-POST it to k8s - how does k8s know which existing manifest this refers to? 我基本上理解了这些内容,但是我没有得到的一件事是:如果我更新一个pod(或副本集)的清单,然后将其重新发布到k8s-k8s如何知道这是指哪个现有清单?

Is this matching done by the manifest's name, ie by the name of the pod or the replica set? 这种匹配是通过清单的名称(即吊舱或副本集的名称)完成的吗? Or …? 要么 …?

In other words: If I update a manifest, how does k8s know that it is an updated one, and how does it detect which one is the one with the previous version? 换句话说:如果我更新的清单,如何K8S知道这是为一个更新的 ,以及它是如何检测哪一个是一个与以前的版本?

You are right, k8s uses metadata.name for identifying resources. 你说得对,K8S使用metadata.name识别资源。 That name is unique per resource type (Pod/ReplicaSet/...) and namespace. 该名称对于每种资源类型(Pod / ReplicaSet / ...)和名称空间都是唯一的。

Well, for starters lets get things straight. 好吧,对于初学者来说,让事情变得简单吧。 When you update manifest, it is obvious what to update in the first place - the object you updated - ie. 当您更新清单时,很明显首先要更新的内容-您更新的对象-即。 Deployment or ReplicaSet. 部署或副本集。 Now, when that is updated, the RollingUpdate kicks in, and this is what I assume you wonder about as well as in general how ownership of pod is established. 现在,当更新时,RollingUpdate会启动,这是我认为您想知道的以及通常如何建立pod所有权的原因。 If you make a kubectl get pod -o yaml you can find a keys like ownerReferences , pod-template-hash and kubernetes.io/created-by which should be rather obvious when you see the content. 如果您使kubectl get pod -o yaml ,则可以找到诸如ownerReferencespod-template-hashkubernetes.io/created-by类的键,当您看到内容时,它们应该非常明显。 In the other direction (so not from the Pod but from Deployment) you have a selector field which defines what labels are used to filter pods to find the right ones. 在另一个方向上(不是从Pod而是从Deployment),您有一个选择器字段,该字段定义用于过滤Pod以查找正确标签的标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM