Kubernetes 集群不会将外部 ip 公开为 <nodes> [英] Kubernetes cluster is not exposing external ip as <nodes>

查看:34
本文介绍了Kubernetes 集群不会将外部 ip 公开为 <nodes>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 service.yaml 代码:

Here is my service.yaml code :

kind: Service
apiVersion: v1
metadata:
  name: login
spec:
  selector:
    app: login
  ports:
  - protocol: TCP
    name: http
    port: 5555
    targetPort: login-http
  type: NodePort

我将服务类型写为

type: NodePort

但是当我按下下面的命令时,它不会将外部 IP 显示为节点":

but when i hit command as below it does not show the external ip as 'nodes' :

'kubectl get svc'

这里是输出:

NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP   10.100.0.1     <none>        443/TCP          7h
login        NodePort    10.100.70.98   <none>        5555:32436/TCP   5m

请帮助我理解错误.

推荐答案

您的服务没有任何问题,您应该可以使用 :32436 访问它.

There is nothing wrong with your service, you should be able to access it using <your_vm_ip>:32436.

NodePort,顾名思义,在所有节点(VM)上打开一个特定的端口,发送到这个端口的任何流量都会转发到服务.因此,在您的节点上,32436 端口是开放的,它将接收该端口上的所有外部流量并将其转发到登录服务.

NodePort, as the name implies, opens a specific port on all the Nodes (the VMs), and any traffic that is sent to this port is forwarded to the service. So, On your node port 32436 is open and will receive all the external traffic on this port and forward it to the login service.

nodePort 是集群外的客户端将看到"的端口.nodePort 通过 kube-proxy 在集群中的每个节点上打开.使用 iptables magic Kubernetes (k8s) 然后将流量从该端口路由到匹配的服务 pod(即使该 pod 运行在完全不同的节点上).

nodePort is the port that a client outside of the cluster will "see". nodePort is opened on every node in your cluster via kube-proxy. With iptables magic Kubernetes (k8s) then routes traffic from that port to a matching service pod (even if that pod is running on a completely different node).

nodePort 是唯一的,因此 2 个不同的服务不能分配相同的 nodePort.声明后,k8s 主节点为该服务保留该节点端口.然后在每个节点(主节点和工作节点)上打开 nodePort - 也不运行该服务的 pod 的节点 - k8s iptables magic 负责路由.这样你就可以从 k8s 集群外部向 nodePort 上的任何节点发出服务请求,而不必担心是否在那里安排了 pod.

nodePort is unique, so 2 different services cannot have the same nodePort assigned. Once declared, the k8s master reserves that nodePort for that service. nodePort is then opened on EVERY node (master and worker) - also the nodes that do not run a pod of that service - k8s iptables magic takes care of the routing. That way you can make your service request from outside your k8s cluster to any node on nodePort without worrying whether a pod is scheduled there or not.

请参阅以下文章,它展示了公开服务的不同方式:

See the following article, it shows different ways to expose your services:

https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0

这篇关于Kubernetes 集群不会将外部 ip 公开为 &lt;nodes&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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