简体   繁体   English

多节点 Virtualbox 驱动程序 Minikube 上的 Ingress Niginx

[英]Ingress Niginx on Multi-Node Virtualbox Driver Minikube

I am following this tutorial for setting up Ingress with Ingress-Nginx on Minikube.我正在按照本教程在 Minikube 上使用 Ingress-Nginx 设置 Ingress。 But I can't seem to get it to work.但我似乎无法让它工作。 I get a connection refused when I try to connect to port 80 on the VM IP address returned by minikube ip当我尝试连接到 minikube minikube ip返回的 VM IP 地址上的端口 80 时,连接被拒绝

My setup is this:我的设置是这样的:

  • Minikube version : v1.25.1 Minikube 版本:v1.25.1
  • VirtualBox version : 6.1 VirtualBox 版本:6.1
  • Kubernetes version : v1.22.5 Kubernetes 版本:v1.22.5

The ingress-nginx namespace has the below resources: ingress-nginx 命名空间具有以下资源:

NAME                                            READY   STATUS    RESTARTS   AGE
pod/ingress-nginx-controller-85f4c5b458-2dhqh   1/1     Running   0          49m

NAME                                         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
service/ingress-nginx-controller             NodePort    10.102.88.109   <none>        80:30551/TCP,443:31918/TCP   20h
service/ingress-nginx-controller-admission   ClusterIP   10.103.134.39   <none>        443/TCP                      20h

NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/ingress-nginx-controller   1/1     1            1           20h

NAME                                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/ingress-nginx-controller-85f4c5b458   1         1         1       20h

NAME                                       COMPLETIONS   DURATION   AGE
job.batch/ingress-nginx-admission-create   1/1           6s         20h
job.batch/ingress-nginx-admission-patch    1/1           6s         20h

The default namespace has the below resources默认命名空间具有以下资源

NAME                       READY   STATUS    RESTARTS   AGE   IP           NODE           NOMINATED NODE   READINESS GATES
pod/web-79d88c97d6-rvp2r   1/1     Running   0          47m   10.244.1.4   minikube-m02   <none>           <none>

NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE   SELECTOR
service/kubernetes   ClusterIP   10.96.0.1      <none>        443/TCP          20h   <none>
service/web          NodePort    10.104.20.14   <none>        8080:31613/TCP   20h   app=web

NAME                                        CLASS   HOSTS              ADDRESS     PORTS   AGE
ingress.networking.k8s.io/example-ingress   nginx   hello-world.info   localhost   80      20h

Minikube is exposing these services: Minikube 公开了这些服务:

|---------------|------------------------------------|--------------|-----------------------------|
|   NAMESPACE   |                NAME                | TARGET PORT  |             URL             |
|---------------|------------------------------------|--------------|-----------------------------|
| default       | kubernetes                         | No node port |
| default       | web                                |         8080 | http://192.168.59.106:31613 |
| ingress-nginx | ingress-nginx-controller           | http/80      | http://192.168.59.106:30551 |
|               |                                    | https/443    | http://192.168.59.106:31918 |
| ingress-nginx | ingress-nginx-controller-admission | No node port |
| kube-system   | kube-dns                           | No node port |
| kube-system   | registry                           | No node port |
|---------------|------------------------------------|--------------|-----------------------------|

In step 4 of the Create an Ingress section The tutorial mentions this:创建 Ingress部分的第 4 步教程中提到了这一点:

Add the following line to the bottom of the /etc/hosts file on your computer (you will need administrator access):

172.17.0.15 hello-world.info

Note: If you are running Minikube locally, use minikube ip to get the external IP. The IP address displayed within the ingress list will be the internal IP. 

It's a three node cluster using VirtualBox.这是一个使用 VirtualBox 的三节点集群。 I've tried adding the Minikube ingress-nginx-controller service's IP (192.168.59.106, which is also the result of minikube ip) to my hosts file, but it doesn't work.我尝试将 Minikube ingress-nginx-controller 服务的 IP(192.168.59.106,这也是 minikube ip 的结果)添加到我的主机文件中,但它不起作用。 And as far as I know, I can't include the service's node port 30551 in the hosts file to test that.据我所知,我不能在主机文件中包含服务的节点端口 30551 来测试它。

Some guidance on how to get this working would be much appreciated非常感谢有关如何使这项工作的一些指导

You are correct.你是对的。 You cannot include the port in the /etc/hosts file.您不能在/etc/hosts文件中包含该端口。 To get there, you would need to specify the full path in your browser or some other application as following (assuming no connectivity issues):要到达那里,您需要在浏览器或其他一些应用程序中指定完整路径,如下所示(假设没有连接问题):

  • hello-world.info:30551

I'd recommend you to tell specifically what type of issue you have.我建议您具体说明您遇到的问题类型。 There can be multiple issues and each one will have different solution.可能有多个问题,每个问题都有不同的解决方案。

For example there will be a difference between the inability to access the Service and getting the 404 message.例如,无法访问服务和收到404消息之间会有区别。


I'm not sure if it's related but I had connectivity issues when I created a cluster in a following way:我不确定它是否相关,但是当我通过以下方式创建集群时遇到了连接问题:

  • minikube start --driver="virtualbox"
  • minikube node add
  • minikube node add

However, when I ran below command, I encountered noone:但是,当我运行以下命令时,我没有遇到任何人:

  • minikube start --driver="virtualbox" --nodes=3

Assuming that you would like to expose your Nginx Ingress controller to be available on the ports 80 and 443 instead of NodePort's you can do:假设您想公开您的Nginx Ingress controller在端口80443上可用,而不是在NodePort's可用,您可以这样做:

apiVersion: v1                                                                                                                                     
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 192.168.59.200-192.168.59.210"
  • Change the Service of your: ingress-nginx-controller to LoadBalancer instead of NodePort ( kubectl edit svc -n ingress-nginx ingress-nginx-controller )将您的服务ingress-nginx-controller更改为LoadBalancer而不是NodePort ( kubectl edit svc -n ingress-nginx ingress-nginx-controller )
  • Check on the Service :检查服务
    • kubectl get svc -n ingress-nginx ingress-nginx-controller
NAME                       TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)                      AGE
ingress-nginx-controller   LoadBalancer   10.106.63.253   192.168.59.201   80:30092/TCP,443:30915/TCP   23m
  • Put the EXTERNAL-IP of your Ingress controller to your /etc/hosts file.Ingress controllerEXTERNAL-IP放到/etc/hosts文件中。
  • Create an Ingress resource that is matching what you've inputted as a name to /etc/hosts and has some backend.创建一个与您输入的/etc/hosts名称相匹配的Ingress资源,并具有一些后端。

Additional resources:其他资源:

When following the tutorial , I enabled the ingress addon after creating my cluster by running minikube addons enable ingress按照教程进行操作时,我在创建集群后通过运行minikube addons enable ingress启用了入口插件

This appeared to succeed, but when trying to connect to port 80 on the IP address returned by minikube ip (which is also the ingress-nginx-controller minikube service address), I got a connection refused.这似乎成功了,但是当尝试连接到minikube ip (这也是 ingress-nginx-controller minikube 服务地址)返回的 IP 地址上的端口 80 时,我得到了一个连接被拒绝。 This can be validated by running:这可以通过运行来验证:

nc -zv $(minikube ip) 80

However, when I enabled ingress at the time of initial cluster creation with this command:但是,当我使用此命令在初始集群创建时启用入口时:

minikube start --driver=virtualbox \
--kubernetes-version=v1.22.5 --nodes 3 \
--addons=ingress

and then ran nc -zv $(minikube ip) 80 , the connection was accepted.然后运行nc -zv $(minikube ip) 80 ,连接被接受。 I'm not sure if this is an issue with Minikube or with VirtualBox, but enabling ingress at the initial cluster creation time rather then subsequently worked for me我不确定这是否是 Minikube 或 VirtualBox 的问题,但在初始集群创建时启用入口,而不是随后为我工作

I was then able to update my hosts file with just the IP of the minikube node and the hello-world.info host然后,我可以仅使用 minikube 节点的 IP 和 hello-world.info 主机来更新我的主机文件

One thing that might also be worth noting if you create and delete your clusters a lot, I found sometimes when updating the hosts file on a Mac that old IPs were being cached.如果您经常创建和删除集群,还有一件事可能值得注意,我有时在更新 Mac 上的主机文件时发现旧 IP 被缓存。 Running sudo dscacheutil -flushcache may help with this运行sudo dscacheutil -flushcache可能对此有所帮助

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

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