将Kubernetes集群公开到Internet [英] Expose Kubernetes cluster to Internet
问题描述
我已经在虚拟机上创建了一个Kubernetes集群,并且我一直试图通过自己的域将它公开给Internet(例如,
I have created a Kubernetes cluster on my virtual machine and I have been trying to expose this to Internet with my own domain(for eg, www.mydomain.xyz). I have created an ingress resource as below and I've also modified kubelet configuration to have my domain name. All my pods and services are created in this domain name (Eg, default.svc.mydomain.xyz)
root@master-1:~# kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
test-ingress <none> www.mydomain.xyz 192.168.5.11 80 5d20h
root@master-1:~# kubectl get svc -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller LoadBalancer 10.103.59.116 192.168.5.11 443:30740/TCP,80:31894/TCP 6d21h
我尝试如下在域DNS页面中添加A记录,但无法添加.
I tried to add A record in my domain DNS page as below and could not add it.
这是我遇到的问题,无法继续进行下去.我是否需要更改群集中的任何内容以在域DNS配置"域中添加此名称空间? (Hostinger)或要添加到主节点中的任何内容.
This is where I get stuck and unable to proceed further. Do I need to change anything in the cluster to add this namespace in "Domain DNS configuration" (Hostinger) or anything to be added in master node.
我拥有的域如何将所有流量重定向到我的kubernetes集群?
How does the domain that I own redirect all the traffic to my kubernetes cluster?
任何帮助将不胜感激.
推荐答案
您无法像尝试过的那样公开Kubernetes集群.
我强烈建议您使用其他Kubernetes解决方案,因为minikube
更像是官方网站上所述的实验和开发工具:
I strongly advise to use a different Kubernetes solution as minikube
is more a tool to experiment and develop as said in the official site:
Minikube是一种可以轻松在本地运行Kubernetes的工具. Minikube在笔记本电脑的虚拟机(VM)内运行一个单节点Kubernetes集群,以供希望试用Kubernetes或使用它进行日常开发的用户使用.
Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a Virtual Machine (VM) on your laptop for users looking to try out Kubernetes or develop with it day-to-day.
请查看其他解决方案,例如:
Please take a look on other solutions like:
- Kubernetes.io:生产环境:创建集群kubeadm
- Github.com:Kubespray
- Cloud.google.com:Kubernetes引擎
- Aws.amazon.com:EKS
- Kubernetes.io: Production environment: Create cluster kubeadm
- Github.com: Kubespray
- Cloud.google.com: Kubernetes Engine
- Aws.amazon.com: EKS
尝试从专用网络向Internet公开Kubernetes时,您要记住几件事.
You have several things to remember when trying to expose Kubernetes to the Internet from your private network.
- 访问公共IP
- 能够在网络内部移植转发流量
- 允许访问您的
minikube
实例的流量 - 结合以上所有内容
- Access to public IP
- Ability to port forward traffic inside your network
- Allow traffic to your
minikube
instance - Combining all of the above
我为什么认为它是
minikube
实例?
您有2个网络接口:
-
NAT
-
Host-only
NAT
Host-only
使用Virtualbox运行minikube
时会创建此接口
This interfaces are getting created when you run your minikube
with Virtualbox
访问公共IP
访问公共IP至关重要. 没有它,您将无法在Internet上公开您的服务.有一些例外情况,但在此我将不重点讨论.
Access to public IP
Access to public IP is crucial. Without it you will not be able to expose your services to the Internet. There are some exclusions but I will not focus on them here.
在DNS面板中,您输入了专用IP地址.除非打算将DNS服务器仅解析本地查询(您的专用网络),否则您不能这样做.为了允许其他用户连接到您的Kubernetes集群,您需要提供一个公共IP地址
就像94.XXX.XXX.XXX
.
In the DNS panel you've entered the private IP address. You cannot do that unless the DNS server is intended resolve only local queries (your private network). To allow other users to connect to your Kubernetes cluster you need to provide a public IP address
like 94.XXX.XXX.XXX
.
您可以在此处详细了解公共IP地址和私有IP地址之间的区别:
You can read more about differences between public and private ip addresses here: