如何从Pod访问本地计算机

编程入门 行业动态 更新时间:2024-10-26 08:32:47
本文介绍了如何从Pod访问本地计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在本地计算机上创建了一个Pod.我在本地计算机上也有一个脚本文件.我想从容器中运行该脚本文件(我将在容器中并运行本地主机上存在的脚本).

I have a pod created on the local machine. I also have a script file on the local machine. I want to run that script file from the pod (I will be inside the pod and run the script present on the local host).

该脚本将更新另一个Pod的/etc/hosts .有没有一种方法可以从另一个Pod更新一个Pod的/etc/hosts ?这些Pod是从两个不同的部署中创建的.

That script will update /etc/hosts of another pod. Is there a way where i can update the /etc/hosts of one pod from another pod? The pods are created from two different deployments.

推荐答案

我想从容器中运行该脚本文件(我将在容器中并运行本地主机上存在的脚本).

I want to run that script file from the pod (I will be inside the pod and run the script present on the local host).

您不能那样做.在普通的Docker上下文中,Docker的主要优势之一是文件系统隔离,因此,除非将容器的某些部分显式发布到容器中,否则容器根本看不到主机的文件系统.在Kubernetes中,不仅存在此限制,而且您对运行在哪个节点上的控制也受到限制,而且如果一个节点具有给定脚本而另一个节点没有给定脚本,则可能会出现问题.

You can't do that. In a plain Docker context, one of Docker's key benefits is filesystem isolation, so the container can't see the host's filesystem at all unless parts of it are explicitly published into the container. In Kubernetes not only is there this restriction, but you also have limited control over which node you're running on, and there's potential trouble if one node has a given script and another doesn't.

有没有一种方法可以从另一个吊舱更新一个吊舱的/etc/hosts ?

作为一般规则,您应该避免对任何东西使用/etc/hosts .设置DNS服务可以使事情保持一致,并避免在多个地方手动编辑文件.

As a general rule, you should avoid using /etc/hosts for anything. Setting up a DNS service keeps things consistent and avoids having to manually edit files in a bunch of places.

Kubernetes为您提供DNS服务.特别是,如果您定义服务,则该服务的名称将显示为DNS名称(在群集中);一个Pod可以通过 first-service-name.default.svc.cluster.local 到达另一个Pod.这可能就是您真正要寻找的答案.

Kubernetes provides a DNS service for you. In particular, if you define a Service, then the name of that Service will be visible as a DNS name (within the cluster); one pod can reach the other via first-service-name.default.svc.cluster.local. That's probably the answer you're actually looking for.

(如果您确实只有一个单节点环境,那么Kubernetes会增加很多复杂性并且没有太大好处;请考虑使用普通的Docker和Docker Compose.)

(If you really only have a single-node environment then Kubernetes adds a lot of complexity and not much benefit; consider plain Docker and Docker Compose instead.)

更多推荐

如何从Pod访问本地计算机

本文发布于:2023-10-15 01:19:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492819.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计算机   Pod

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!