简体   繁体   English

Kubernetes公开服务未分配外部IP

[英]Kubernetes expose a service does not assign the external ip

I have an internal service that is created via the first cmd. 我有一个通过第一个cmd创建的内部服务。 Then i run kubectl expose on that service that is created. 然后,我在创建的服务上运行kubectl暴露。

kubectl -n XXX create -f service.yml
kubectl -n XXX get svc
NAME                                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                                            AGE
foo                           ClusterIP   10.152.183.41    <none>        8089/TCP


kubectl -n XXX expose service foo --type=NodePort --name=foo-ext
kubectl -n XXX get svc
NAME                                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                                            AGE
foo                           ClusterIP   10.152.183.41    <none>        8089/TCP                                                                           29m
foo-ext                   NodePort    10.152.183.177   <none>        8089:30406/TCP

Where the external ip is I would have figured kubectl expose would have assigned an external ip to the external service, is there an additional flag i need to pass? 我将在哪里知道外部ip的kubectl公开将外部IP分配给外部服务,我是否需要传递其他标志?

According to the Kubernetes docs : 根据Kubernetes的文档

If you set the type field to NodePort, the Kubernetes master will allocate a port from a range specified by --service-node-port-range flag (default: 30000-32767), and each Node will proxy that port (the same port number on every Node) into your Service. 如果将类型字段设置为NodePort,则Kubernetes主服务器将在--service-node-port-range标志指定的范围内分配端口(默认值:30000-32767),并且每个Node将代理该端口(同一端口)每个节点上的数字)添加到您的服务中。

So, Kubernetes will ensure that the same port number is exposed on all nodes that are hosting this service. 因此,Kubernetes将确保在托管此服务的所有节点上公开相同的端口号。 The external IP, in this case, is the IP address of the node. 在这种情况下,外部IP是节点的IP地址。

Whereas Kubernetes says this about External IPs : 而Kubernetes这样说是关于外部IP的

If there are external IPs that route to one or more cluster nodes, Kubernetes services can be exposed on those externalIPs. 如果存在路由到一个或多个群集节点的外部IP,则可以在这些外部IP上公开Kubernetes服务。 Traffic that ingresses into the cluster with the external IP (as destination IP), on the service port, will be routed to one of the service endpoints. 使用服务端口上的外部IP(作为目标IP)进入群集的流量将被路由到服务端点之一。 externalIPs are not managed by Kubernetes and are the responsibility of the cluster administrator. externalIPs IP不是由Kubernetes管理的,而是集群管理员的责任。

The downside to a NodePort type of service is that, by itself, it's not a scalable approach and lacks service discoverability. NodePort服务类型的缺点在于,它本身不是可伸缩的方法,并且缺乏服务可发现性。

If you want to expose a service through a single IP address to consumers outside of your Kubernetes cluster, you may want to look into LoadBalancer type of service if have a public cloud or hybrid cloud Kubernetes deployment, or you may want to look into Ingress if you have an on-premises Kubernetes deployment. 如果您想通过单个IP地址向Kubernetes集群外部的使用者公开服务,则如果要部署公共云或混合云Kubernetes,则可能需要研究LoadBalancer类型的服务,或者如果需要通过Ingress来研究Ingress您有一个本地Kubernetes部署。

LoadBalacer type service "assigns" an external IP, but it is cloud provider specific, so it won't work. LoadBalacer类型服务“分配”了一个外部IP,但它是特定于云提供商的,因此将无法使用。 Unless you have a load balancer pointing to the cluster (with an external IP, of course). 除非您有一个指向集群的负载均衡器(当然是带有外部IP)。

From the other services, your only option would be NodePort type service, which would map your pod port to a port on the node, so it will be accessible from outside world. 在其他服务中,唯一的选择是NodePort类型服务,该服务会将您的Pod端口映射到节点上的端口,因此可以从外部访问。 The ugly part is that it is going to be on a port like 30021 (between 30000-32767). 丑陋的部分是它将要放在类似30021的端口上(介于30000-32767之间)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM