kubernetes - Kubernetes 中的 ClusterIP、NodePort 和 LoadBalancer 服务类型有什么区别?

标签 kubernetes containers kubernetes-service

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

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: 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: 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但只是在不同的端口,哪个端口对外部客户端开放?所以在这种情况下是 <NodeIP>:<NodePort><ClusterIP>:<NodePort> 相同?

或者是NodeIP实际上是你运行kubectl get nodes时发现的IP而不是用于 ClusterIP 服务类型的虚拟 IP?

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

enter image description here

是否有任何特殊原因导致 Client位于 Node 内?我认为它需要位于 Cluster 内如果是 ClusterIP 服务类型?

如果为 NodePort 绘制相同的图,则将客户端完全绘制在 Node 之外是否有效?和Cluster还是我完全没有捕获要点?

最佳答案

ClusterIP 公开以下内容:

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

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

NodePort 公开以下内容:

  • <NodeIP>:spec.ports[*].nodePort
  • spec.clusterIp:spec.ports[*].port

如果您从节点的外部 IP 在 nodePort 上访问此服务,它会将请求路由到 spec.clusterIp:spec.ports[*].port ,这会将其路由到您的 spec.ports[*].targetPort ,如果设置。该服务也可以通过与ClusterIP相同的方式访问。

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

LoadBalancer 公开以下内容:

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

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

关于kubernetes - Kubernetes 中的 ClusterIP、NodePort 和 LoadBalancer 服务类型有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41509439/

相关文章:

c++ - C++ 中的递归容器?

kubernetes - Kubernetes 服务如何决定路由到哪个后端 pod

azure - Kubernetes 与 Dynatrace 集成,dynatrace-webhook 抛出错误

kubernetes - 在 Kubernetes 中更新 configmap 时刷新 daemonset pod

kubernetes - 如何快速使Kubernetes Readiness探针失败?

docker - portMappings中dcos json中容器端口、主机端口和服务端口的区别

docker - 在运行的docker容器中设置环境变量

kubernetes - Kubernetes 中的自定义负载均衡

kubernetes - Kubernetes Pod 之间的通信

kubernetes 持久卷 ReadWriteOnly(RWO) 不适用于 nfs