我有2个在minikube上运行的 pod 。 Pod A必须将Pod B expose 2 ports
和inside the k8 cluster
都编码为outside k8 cluster
8081和9092,以便Pod B可以到达它们,并且消费者也可以在群集之外访问它们。所以我的问题是should
我为每个端口都创建了2 services
吗?
一种公开为群集ip,另一种公开为节点端口?还是有一种方法可以创建一个服务来将其作为群集IP和NodePort公开?
另外,如果我必须将节点端口公开为特定端口,则指定nodePort
是否会与群集ip混淆?
最佳答案
当您选择NodePort
服务类型时,除了具有群集IP外,kubernetes还将在群集每个节点上的端口(每个节点上的相同端口)上公开该服务。因此,选择NodePort可以同时获得:ClusterIP和每个节点上的端口。
如in the docs
Note that this Service will be visible as both :spec.ports[].nodePort and spec.clusterIP:spec.ports[].port.
关于kubernetes - 是否可以创建一个服务以将其同时显示为群集IP和NodePort?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48751810/