首页 文章

在K8S中链接POD中的容器

提问于
浏览
1

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

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

这是日志中出现的内容:
logs

这是错误图像:
error

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

2 回答

  • 1

    您不需要链接它们 . 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 .

  • 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” .

相关问题