从kubernetes主服务器通过PortForward访问NodePort [英] Access NodePort through PortForward from the kubernetes master
问题描述
我所拥有的:具有三个节点的GCE上的Kubernetes集群.假设主机具有IP <MasterIP>
.另外,我在类型NodePort的群集中有一个服务,该服务侦听端口<PORT>
.我可以使用<NodeIP>:<PORT>
What I Have: A Kubernetes Cluster on GCE with three Nodes. Lets suppose the master has the IP <MasterIP>
. Additionally I have a Service within the cluster of Type NodePort which listens to the port <PORT>
. I can access the service using <NodeIP>:<PORT>
我要做什么:使用<MasterIP>:<PORT>
访问服务如何将端口从<MasterIP>
转发到群集内?换句话说:<MasterIP>:<PORT> --> <NodeIP>:<PORT>
What I would like to do: Access the service with <MasterIP>:<PORT>
How can I forward the port from <MasterIP>
to within the cluster? in other words: <MasterIP>:<PORT> --> <NodeIP>:<PORT>
之所以要这样做,是因为我不想依赖特定的NodeIP
,因为Pod可以重新安排到另一个Node.
The reason why I would like to do this is simply I don't want to rely on a specific NodeIP
since the Pod can be rescheduled to another Node.
谢谢
推荐答案
带有type: NodePort
的Kubernetes Service
在每个节点上打开相同的端口,并使用内部IP路由将流量发送到当前计划了pod的任何地方.您应该可以通过<AnyNodeIP>:<PORT>
访问该服务.
A Kubernetes Service
with type: NodePort
opens the same port on every Node and sends the traffic to wherever the pod is currently scheduled using internal IP routing. You should be able to access the service at <AnyNodeIP>:<PORT>
.
在Google的Kubernetes集群中,主计算机不可用于路由流量.可靠地公开服务的方法是将Service
与type: LoadBalancer
一起使用,这将提供一个解析为您的服务的IP,而不管哪个节点启用或它们的IP是什么.
In Google's Kubernetes cluster, the master machines are not available for routing traffic. The way to reliably expose your services is to use a Service
with type: LoadBalancer
which will provide a single IP that resolves to your service regardless of which Nodes are up or what their IPs are.
这篇关于从kubernetes主服务器通过PortForward访问NodePort的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!