Kubernetes 临时容器

Kubernetes Ephemeral Containers

我们正在使用 Python Docker SDK 在 Kubernetes 中创建临时容器。我的问题是这些新容器是否也将与 pod 中的其他容器共享相同的网络?换句话说,这个新创建的临时容器可以访问使用本地主机创建它的原始容器吗?

My question is if these new containers will also share the same networking as the other containers in the pod?

是的。尽管 Pod 中的容器共享 IP 地址和网络 space.

的短暂 container networking is not documented per se. Essentially, an ephemeral container runs in a Pod and it's well described in the docs 的特定性质

✌️

为了让未来的访客更深入地了解容器和 Pods:

My question is if these new containers will also share the same networking as the other containers in the pod?

@Rico 说得对 - 是的。基本上,当 Kubernetes 将 Pod 调度到节点上的 运行 时,它会在节点的 Linux 内核中为 Pod 创建一个“网络命名空间”。同一个 Pod 中的所有容器共享同一个网络命名空间。

In other words, can this newly created ephemeral container access the original container that created it using localhost?

我认为你不能这样改写你的第一个问题,它们是不同的问题。这个问题的答案是否定的——一旦 Container 被销毁,就无法访​​问该 Container(或其任何状态),这就是短暂性的全部意义所在。另外,您说的是“创建它的原始容器”——不是容器创建了另一个容器,是 Kubernetes 在旧容器因某些原因崩溃时创建了新容器。