kubernetes POD IP何时更改? [英] When will the kubernetes POD IP change?

查看:551
本文介绍了kubernetes POD IP何时更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将单片应用程序移植到k8s pods.从理论上讲,吊舱被视为短暂的,建议使用服务概念来提供静态IP.但是到目前为止,在我的测试中,我还没有看到POD IP被更改.那么现在的问题是,k8s何时将新IP分配给我的POD?

I am trying to port a monolithic app to k8s pods. In theory, pods are considered ephemeral and it is suggested to use service concept to provide a static IP. But in my test so far, I have not seen the POD IP being changed. So now the question when will k8s assign a new IP to my POD?

我用固定的主机名创建了POD(不使用任何控制器),并且它们绑定到单个节点.因此,节点和主机名将永远不会更改,POD将永远不会被删除吗?因此,在这种独特情况下,POD IP何时可以更改.我看了看文档,这对我来说还不清楚.

I have created POD (without using any controller) with fixed hostname and they are bounded to a single node. So the node and the hostname will never change and the POD will never be deleted? So in this unique case, when can the POD IP change. I looked at the documentation and this is not clear to me.

推荐答案

正如 coderanger 所述,您不应依赖在Pod本身上,因为Pod是短暂且可更换的.由于Pod是Kubernetes中最小的可部署对象,并且被认为是易于更换的,因此我们应避免与Pod本身直接交互.相反,我们应该与负责Pod的控制器交互. David Maze 提到您应该使用该服务来管理广告连播.我的前任的意思是,在对Pod进行任何更改后,它可能会导致Pod的删除,失败后它将停止工作,并且如果您与带有控制器的Pod进行交互,则会导致重新创建. 因此,更明确地说-您的问题是如果我不使用最佳实践以及与群集进行交互的建议方式,将会发生什么".答案是-许多事情可能出错,其中之一就是错误和许多不必要的故障排除方法.因此,我们建议您遵守Kubernetes社区和文档提供的一组规则: 如此处:

As the coderanger mentions, you should not rely on the pod itself as Pods are ephemeral and replaceable. As the Pod is the smallest deployable object in Kubernetes and is considered to be easily replaceable, we should avoid direct interaction with a pod itself; instead, we should interact with the controller which will take care of the Pod. David Maze mentions that you should use the service for managing the pod/pods. What did my predecessors mean is that after you do any changes to the Pod, it might result in a deletion of the pod, after failure it would stop working and if you would interact with your Pod with controllers it would result in recreating. So to be more clear - your question is "if I will not use the best practices and the advised way of interacting with my cluster what will happen". The answer is - many things can go wrong, and one of them is errors and a lot of unnecessary troubleshooting for you. So what do we advise to you is complying with the set of rules provided by the Kubernetes community and documentation: As stated here:

通常,只有在有人摧毁荚果之后,荚果才会消失.这 可能是人还是控制者.该规则的唯一例外是 phase成功或失败的Pod的数量超过某些 持续时间(由主机中的terminated-pod-gc-threshold确定) 将会过期并被自动销毁.

In general, Pods do not disappear until someone destroys them. This might be a human or a controller. The only exception to this rule is that Pods with a phase of Succeeded or Failed for more than some duration (determined by terminated-pod-gc-threshold in the master) will expire and be automatically destroyed.

即使在单例情况下,也应该几乎始终使用控制器;控制器具有很多优点,例如自我修复或复制等.正如 coderanger 所述,StatefullSets还可以为有状态的Pod提供支持. .有关Pod的耐用性的更多信息,请在此处.

You should almost always use a controller even in your singleton scenario; controllers provide a lot of advantages like self-healing or replication etc. As coderanger mentioned, StatefullSets can also provide support to stateful pods. More about the durability of Pods here.

更进一步,我们使用了不同类型的控制器,因此您可以避免直接与广告连播互动: -工作用于预计将终止的Pod - ReplicationController 部署用于预计不会终止的Pod - DaemonSet 需要在每台计算机上运行一个的Pod,因为它们提供了机器特定的系统服务

Going further we use different types of controllers, so you can avoid direct interaction with a pod: - Job for Pods that are expected to terminate - ReplicationController, ReplicaSet, or Deployment for Pods that are not expected to terminate - DaemonSet Pods that need to run one per machine, because they provide a machine-specific system service

之所以这样,是因为控制器具有弹性,并且能够承受Pod不会出现的机器故障.豆荚不是耐久的实体,不应像对待豆荚那样对待.他们将无法生存计划错误,节点故障(资源驱逐不足)等

The reason for that is because controllers are resilient and they will survive machine failures which Pods will not. Pods are not durable entities and should not be treated like that. They will not survive scheduling errors, node failures (lack of resource evictions), etc.

直接讨论问题的实质,由于Kubernetes的性质,您不能为Pod分配静态IP.硬编码主机名不是一个好主意,最接近解决方案的方法是按照@coderanger的建议创建StatefullSet,它或多或少会为您的Pod提供一个静态主机名.

Going directly to the essence of the question, you can't assign a static IP to the Pod because of the nature of Kubernetes. Hardcoding the hostname is not a good idea, the closest you can get to your solution is creating StatefullSet as advised by the @coderanger, which will more or less give your Pod a static hostname.

这篇关于kubernetes POD IP何时更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆