docker - Kubernetes NodePort 类型端点和端口

标签 docker kubernetes

按照 kubernetes.io 上的交互式教程进行操作其中 NodePort类型服务是通过 kubectl expose deploy kubernetes-bootcamp --type="NodePort" --port 8080 创建的我对结果感到困惑。

首先教程指出

Let's run (...) kubectl get services (...) we see that the service received (...) an external-IP (the IP of the Node).

根据输出,这不是真的,没有外部 IP:

NAME                TYPE        CLUSTER-IP      EXTERNAL-IP PORTS
kubernetes-bootcamp NodePort    ...             <none>      8080:31479

现在与 kubectl describe service kubernetes-bootcamp一个得到:

Type        NodePort
IP          ...
Port        <unset> 8080/TCP
NodePort    <unset> 31479/TCP

现在教程建议curl $(minikube ip):$NODE_PORT等于 curl <internal node IP>:<NodePort> - 这有效,但留下了很多问题:

  • 根据kubectl expose -h --port命令指定要提供服务的端口,因此我期望 --port设置暴露<NodePort>对于 NodePort类型服务,但事实并非如此。为什么以及如何设置?
  • <internal node IP>在服务元数据中没有显示容器应用程序确实可以到达的位置,我只能从 kubectl get nodes 获取它。为什么?
  • IP通过kubectl describe service显示(等于集群 IP)与此处显示的端口(等于通过 --port 设置的端口)相结合也会路由到容器应用程序,因此 curl <clusterIP>:8080工作并履行 promise ,您可以通过 --port 设置暴露的端口。但以一种意想不到的方式:为什么NodePort服务有这样的clusterIP类型接口(interface)?
  • Endpoints 的含义是什么?通过kubectl describe service显示如果既不是 clusterIP端点也不是 NodePort端点?

最佳答案

这将有助于解决这个问题,但总的主题是 NodePort 并不是在集群外部公开服务的最常见方式,因此它周围的一些功能并不那么直观。 LoadBalancer(或使用它的入口 Controller )是向集群外部公开服务的首选方式。

The IP shown through kubectl describe service (which equals the cluster IP) combined with the port also shown there (which equals the one set via --port) also routes to the container app, thus curl <clusterIP>:8080 works and fulfills the promise that you can set the exposed port via --port. But in an unexpected way: why does a NodePort service have such a clusterIP type interface?

您还会看到 ClusterIP,因为这是访问集群内服务的方式。其他服务可以使用该服务名称和端口(本例中为 8080)访问集群内的该服务,但 ClusterIP 本身并不使该服务在集群外部可用。

What is the meaning of the Endpoints shown through kubectl describe service if it is neither the clusterIP endpoint nor the NodePort endpoint?

172.18.0.2:8080 的端点值或类似的内容将是服务的内部 IP 和端口。在集群内,您还可以使用集群的内部 dns 通过名称访问服务(这通常是更方便的方式)。

The <internal node IP> under which the container app can indeed be reached is not shown anywhere in the service metadata, I can only get it from kubectl get nodes. Why?

这链接到您从 kubectl get services 看到的输出点和kubectl describe service <service>当通过 NodePort 公开时有点误导 - 人们会期望看到 external-ip 中或类似的内容为条目。 NodePort 将该节点上的端口专门用于该服务。这有点限制,就好像您对添加的每个服务都这样做一样,那么您将耗尽端口。所以external-ip如果要显示,则必须是节点的 IP,当与 LoadBalancer 类型服务的 IP 一起显示时,这可能看起来有点奇怪。

According to kubectl expose -h the --port command specifies the port on which to serve, thus I expected --port to set the exposed NodePort for NodePort type services, but that is not the case. Why and how to set it?

公开命令行选项特别有限,因为您当前can't even use it to choose which port in the NodePort range is used 。在您的情况下,您已获得外部端口 31479,但您无法选择它。可能不建议让用户太容易地选择,因为可用端口的数量有限,并且您很容易发现自己分配了同一个端口两次。但您可以在通过描述 rune 件部署时选择外部端口。

关于docker - Kubernetes NodePort 类型端点和端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51880663/

相关文章:

Kubernetes (AKS) 上的 MySQL 主节点无故死亡

docker - [kubeadm] 更新 cni 配置时出错

kubernetes - namespace 中的Istio自定义网关

Java Kubernetes 客户端 SSLHandshakeException 扩展 (5) 不应出现在certificate_request中

mongodb - 我如何正确设置Keystone.js应用程序以使其在mongo的docker中运行?

docker - docker网络覆盖是否像http通信一样保护websocket通信

docker - Kubernetes-上传crisocket : timed out waiting for the condition时出错

java - Helm 图表中的 Spring Boot 应用程序属性

kubernetes - Kubebuilder:资源删除没有预期的副作用

docker - 如何在不安全的注册表中列出Docker镜像