同一节点中同一 pod 的多个实例 - Kubernetes

Multiple instance of same pod in same node - Kubernetes

我想 运行 Kubernetes 中同一节点中同一 pod 的多个实例。我为此使用了野蝇 docker 图像。当运行在同一节点中连接多个 pod 时,出现端口冲突异常。

2020-11-30 15:53:17,079 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("core-service" => "management"),
("management-interface" => "http-interface")
]) - failure description: {"WFLYCTL0080: Failed services" => {"org.wildfly.management.http.extensible" => "java.net.BindException: Address already in use /0.0.0.0:9990"}}
2020-11-30 15:53:17,259 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "undertow"),
("server" => "default-server"),
("http-listener" => "default")
]) - failure description: {"WFLYCTL0080: Failed services" => {"org.wildfly.undertow.listener.default" => "Address already in use /0.0.0.0:9575"}}
2020-11-30 15:53:17,260 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "undertow"),
("server" => "default-server"),
("https-listener" => "https")
]) - failure description: {"WFLYCTL0080: Failed services" => {"org.wildfly.undertow.listener.https" => "Address already in use /0.0.0.0:8553"}}
2020-11-30 15:53:17,262 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("core-service" => "management"),
("management-interface" => "http-interface")
]) - failure description: {"WFLYCTL0080: Failed services" => {"org.wildfly.management.http.extensible" => "java.net.BindException: Address already in use /0.0.0.0:9990"}}
2020-11-30 15:53:17,399 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0028: Stopped deployment demo.war (runtime-name: demo.war) in 133ms
2020-11-30 15:53:17,416 ERROR [org.jboss.as.server] (ServerService Thread Pool -- 44) WFLYSRV0021: Deploy of deployment "demo.war" was rolled back with the following fai
lure message: undefined  

那么我怎样才能绕过这个问题和 运行 没有端口冲突的多个实例呢??

仅当您使用 hostPorthostNetwork 时,不同 pods 的端口才可能发生冲突。否则,当 运行 在同一节点中设置多个相同的 pods 时,您应该不会遇到任何问题。

您可以尝试运行以下命令。您的 Wildfly pods 应该 运行 没有任何问题,因为它们使用的端口在容器内。

kubectl run wildfly --image=jboss/wildfly
kubectl run wildfly-2 --image=jboss/wildfly
kubectl run wildfly-3 --image=jboss/wildfly

如果您需要使用 hostPorthostNetwork(不推荐),那么您就只能靠自己了,您需要自己“编排”端口。