【问题标题】:Linking Containers in POD in K8S在 K8S 中连接 POD 中的容器
【发布时间】:2018-01-16 05:36:49
【问题描述】:

我想将我的 selenium/hub 容器链接到 POD 中的 chrome 和 firefox 节点容器。

在 docker 中,它很容易在 docker compose yaml 文件中定义。 我想知道如何在 Kubernetes 中实现这种链接。

这是日志中显示的内容。:
这是错误图片:

apiVersion: v1
kind: Pod
metadata:
  name: mytestingpod
spec:
  containers:
  - name: seleniumhub
    image: selenium/hub
    ports:
    - containerPort: 4444
    hostPort: 4444
  - name: chromenode
    image: selenium/node-chrome-debug
    ports:
    - containerPort: 5901
    links: seleniumhub:hub
  - name: firefoxnode
    image: selenium/node-firefox-debug
    ports:
    - containerPort: 5902
    links: seleniumhub:hub  

2

【问题讨论】:

    标签: docker kubernetes


    【解决方案1】:

    只需使用“Translate a Docker Compose File to Kubernetes Resources”中描述的 kompose:它会将您的 docker-compose.yml 文件转换为 kubernetes yaml 文件。

    然后您将看到 selenium/hub 容器声明如何转换为 kubernetes 配置文件。

    请注意,docker link 已过时。
    请尝试关注kubernetes examples/selenium,它们是described here

    将应用程序与 Kubernetes 连接的方式是通过服务:
    见“Connecting Applications with Services”。

    【讨论】:

    • 即使在使用 kompose 之后,我仍然收到 chrome 未链接到正在运行的集线器容器的错误
    • 另外,使用 kompose 多个 Pod 创建了其中的单个容器,我想要的是一个带有多个容器的单个 Pod
    • @adityarawat 你能用准确的错误信息以及 yaml 文件内容来编辑你的问题吗?
    • @adityarawat 我已经相应地编辑了我的答案。使用链接似乎不是推荐的方法。
    【解决方案2】:

    您不需要链接它们。 Kubernetes 的工作方式是all the containers in the same Pod are already on the same networking namespace,这意味着它们可以通过localhost 和正确的端口相互通信。

    pod 中的应用程序都使用相同的网络命名空间(相同的 IP 和端口空间),因此可以“找到”彼此并使用 localhost 进行通信。因此,Pod 中的应用程序必须协调它们对端口的使用。每个 pod 在一个平面共享网络空间中都有一个 IP 地址,该空间与网络上的其他物理计算机和 pod 进行完全通信。

    如果您想从seleniumhub 容器访问chromenode 容器,只需向 localhost:5901 发送请求即可。

    如果您想从chromenode 容器访问seleniumhub 容器,只需向 localhost:4444 发送请求即可。

    【讨论】:

    • 我将如何向 localhost:4444 或 5901 请求?我必须在 yaml 文件中指定请求吗?
    • 我不知道 seleniumhub 是如何工作的,但我猜你是在 seleniumhub 配置中的某处指定 hub 以连接到 chrome 或 firefox 节点,对吧?不要使用 hub ,而是使用 localhost 和端口。
    猜你喜欢
    • 2021-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-19
    • 2019-10-22
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多