如何从Pod访问本地计算机 [英] How to access local machine from a pod

查看:77
本文介绍了如何从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服务.特别是,如果您定义服务,则

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访问本地计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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