加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

docker – Kubernetes – 使用名称而不是“localhost”在pod

发布时间:2020-12-16 03:33:16 所属栏目:安全 来源:网络整理
导读:来自kubernetes docs: The applications in a pod all use the same network namespace (same IP and port space),and can thus “ find ” each other and communicate using localhost. 是否可以使用一些特定于容器的名称而不是locahost? 例如,使用docke

来自kubernetes docs:

The applications in a pod all use the same network namespace (same IP and port space),and can thus “find” each other and communicate using localhost.

是否可以使用一些特定于容器的名称而不是locahost?

例如,使用docker-compose,您可以使用服务名称进行通信. [docs]

所以,如果我的docker-compose.yml文件是

version: '2'
services:
  web:
    build: .
    ports:
      - "8000:8000"
  srv:
    build: .
    ports:
      - "3000:3000"

然后我通过调用http:// srv:3000 /而不是http:// localhost:3000从web中访问srv

如何在kubernetes中实现相同的行为?有什么方法可以指定在pods的yaml配置中使用什么名称?

localhost只是网络环回设备的名称(IPv4通常为127.0.0.1,IPv6为:: 1).这通常在/ etc / hosts文件中指定.

一个pod有自己的IP,因此每个容器内部共享该IP.如果这些容器应该是独立的(即不需要配置),它们应该都在自己的容器中.然后,您可以为每个允许DNS查找的service定义为来自同一命名空间中的pod的“$SERVICENAME”,或者来自不同命名空间中的pod的“$SERVICENAME.$NAMESPACE”.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读