Kubernetes 中的 ClusterIP、NodePort 和 LoadBalancer 服务类型有什么区别? [英] What's the difference between ClusterIP, NodePort and LoadBalancer service types in Kubernetes?

查看:55
本文介绍了Kubernetes 中的 ClusterIP、NodePort 和 LoadBalancer 服务类型有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题 1 - 我正在阅读文档,但对措辞有些困惑.它说:

Question 1 - I'm reading the documentation and I'm slightly confused with the wording. It says:

ClusterIP:在集群内部 IP 上公开服务.选择此值会使服务只能从集群内部访问.这是默认的 ServiceType

ClusterIP: Exposes the service on a cluster-internal IP. Choosing this value makes the service only reachable from within the cluster. This is the default ServiceType

NodePort:在静态端口(NodePort)处公开每个节点 IP 上的服务.NodePort 服务将路由到的 ClusterIP 服务会自动创建.您将能够从集群外部通过请求 : 联系 NodePort 服务.

NodePort: Exposes the service on each Node’s IP at a static port (the NodePort). A ClusterIP service, to which the NodePort service will route, is automatically created. You’ll be able to contact the NodePort service, from outside the cluster, by requesting <NodeIP>:<NodePort>.

LoadBalancer:使用云提供商的负载均衡器在外部公开服务.外部负载均衡器将路由到的 NodePort 和 ClusterIP 服务会自动创建.

LoadBalancer: Exposes the service externally using a cloud provider’s load balancer. NodePort and ClusterIP services, to which the external load balancer will route, are automatically created.

NodePort 服务类型是否仍然使用 ClusterIP 但只是在不同的端口上,该端口对外部客户端开放?所以在这种情况下 :: 一样吗?

Does the NodePort service type still use the ClusterIP but just at a different port, which is open to external clients? So in this case is <NodeIP>:<NodePort> the same as <ClusterIP>:<NodePort>?

或者 NodeIP 实际上是您运行 kubectl get nodes 时找到的 IP,而不是用于 ClusterIP 服务类型的虚拟 IP?

Or is the NodeIP actually the IP found when you run kubectl get nodes and not the virtual IP used for the ClusterIP service type?

问题 2 - 同样在以下链接的图表中:

Question 2 - Also in the diagram from the link below:

Client 位于 Node 内部有什么特殊原因吗?我认为在 ClusterIP 服务类型的情况下,它需要位于 Cluster 内?

Is there any particular reason why the Client is inside the Node? I assumed it would need to be inside a Clusterin the case of a ClusterIP service type?

如果为 NodePort 绘制了相同的图表,将客户端完全绘制在 NodeCluster 之外是否有效,还是我完全没有抓住重点?

If the same diagram was drawn for NodePort, would it be valid to draw the client completely outside both the Node andCluster or am I completely missing the point?

推荐答案

ClusterIP 公开以下内容:

A ClusterIP exposes the following:

  • spec.clusterIp:spec.ports[*].port

您只能在集群内部访问此服务.它可以从它的 spec.clusterIp 端口访问.如果设置了 spec.ports[*].targetPort,它将从端口路由到目标端口.调用kubectl get services时得到的CLUSTER-IP是集群内部分配给这个服务的IP.

You can only access this service while inside the cluster. It is accessible from its spec.clusterIp port. If a spec.ports[*].targetPort is set it will route from the port to the targetPort. The CLUSTER-IP you get when calling kubectl get services is the IP assigned to this service within the cluster internally.

NodePort 公开以下内容:

A NodePort exposes the following:

  • :spec.ports[*].nodePort
  • spec.clusterIp:spec.ports[*].port

如果您从节点的外部 IP 访问 nodePort 上的此服务,它会将请求路由到 spec.clusterIp:spec.ports[*].port,然后将其路由到您的 spec.ports[*].targetPort(如果已设置).这个服务也可以像ClusterIP一样访问.

If you access this service on a nodePort from the node's external IP, it will route the request to spec.clusterIp:spec.ports[*].port, which will in turn route it to your spec.ports[*].targetPort, if set. This service can also be accessed in the same way as ClusterIP.

您的 NodeIP 是节点的外部 IP 地址.您无法从 spec.clusterIp:spec.ports[*].nodePort 访问您的服务.

Your NodeIPs are the external IP addresses of the nodes. You cannot access your service from spec.clusterIp:spec.ports[*].nodePort.

LoadBalancer 公开以下内容:

A LoadBalancer exposes the following:

  • spec.loadBalancerIp:spec.ports[*].port
  • :spec.ports[*].nodePort
  • spec.clusterIp:spec.ports[*].port

您可以从负载均衡器的 IP 地址访问此服务,它将您的请求路由到 nodePort,然后将请求路由到 clusterIP 端口.您也可以像访问 NodePort 或 ClusterIP 服务一样访问此服务.

You can access this service from your load balancer's IP address, which routes your request to a nodePort, which in turn routes the request to the clusterIP port. You can access this service as you would a NodePort or a ClusterIP service as well.

这篇关于Kubernetes 中的 ClusterIP、NodePort 和 LoadBalancer 服务类型有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆