Kubernetes集群没有将外部IP公开为

Kubernetes集群没有将外部IP公开为

本文介绍了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显示为'nodes':

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

请帮助我理解错误.

推荐答案

您的服务没有任何问题,您应该可以使用<your_vm_ip>: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.然后,在每个节点(主节点和工作节点)上打开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;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:42