如何将Kubernetes服务公开到互联网? [英] How do I expose Kubernetes service to the internet?

查看:66
本文介绍了如何将Kubernetes服务公开到互联网?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Azure上运行具有1个主节点(也是一个节点)和2个节点的kubernetes集群.我正在将Ubuntu与Flannel覆盖网络一起使用.到目前为止,一切工作正常.我唯一的问题是将该服务公开给互联网.

I am running a kubernetes cluster with 1 master (also a node) and 2 nodes on Azure. I am using Ubuntu with Flannel overlay network. So far everything is working well. The only problem I have is exposing the service to the internet.

我正在Azure子网中运行群集.主服务器上附有一个具有公共IP的NIC.这意味着,如果我运行一个侦听端口80的简单服务器,则可以使用域名访问服务器(Azure提供了为公共IP设置域名的选项).

I am running the cluster on an azure subnet. The master has a NIC attached to it that has a public IP. This means if I run a simple server that listens on port 80, I can reach my server using a domain name (Azure gives an option to have a domain name for a public IP).

我还可以通过一些技巧来访问kubernetes留言簿前端服务.我所做的是检查主服务器上的所有侦听端口,并尝试使用公共IP的每个端口.我能够使用kubernetes服务并获得响应.根据我的理解,这是直接转到在主节点(也是一个节点)上运行的Pod,而不是通过服务IP(该IP在所有Pod之间均已实现负载均衡).

I am also able to reach the kubernetes guest book frontend service with some hack. What I did was check all the listening ports on the master and try each port with the public IP. I was able to hit the kubernetes service and get response. Based on my understanding this is directly going to the pod that is running on the master (which is also a node) rather than going through the service IP (which would have load balanced across any of the pods).

我的问题是如何将外部IP映射到服务IP?我知道kubernetes的设置仅适用于GCE(我现在无法使用).但是,有什么巧妙的方法可以告诉etcd/flannel做到这一点?

My question is how do I map the external IP to the service IP? I know kubernetes has a setting that works only on GCE (which I can't use right now). But is there some neat way of telling etcd/flannel to do this?

推荐答案

如果使用kubectl expose命令:

-external-ip =":要为服务设置的外部IP地址.除了其生成的服务IP之外,还可以通过此IP访问该服务.

--external-ip="": External IP address to set for the service. The service can be accessed by this IP in addition to its generated service IP.

或者,如果您是从jsonyaml文件创建的,请使用 spec/externalIPs 数组.

Or if you create from a json or yaml file, use the spec/externalIPs array.

这篇关于如何将Kubernetes服务公开到互联网?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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