在Minkube上具有Nginx入口控制器的Metallb不断重置入口的外部IP

时间:2019-07-14 22:08:57

标签: kubernetes minikube metallb

此处是一个MCVE示例:https://github.com/chrissound/k8s-metallb-nginx-ingress-minikube (只需运行large./init.sh)。

分配给入口的IP不断重置,我不知道是什么原因引起的?也许我需要其他配置吗?

minikube addons enable ingress

一分钟后:

kubectl get ingress --all-namespaces                 
NAMESPACE       NAME          HOSTS         ADDRESS           PORTS     AGE
chris-example   app-ingress   example.com   192.168.122.253   80, 443   61m

在配置方面,我刚刚应用了

NAMESPACE       NAME          HOSTS         ADDRESS   PORTS     AGE
chris-example   app-ingress   example.com             80, 443   60m

ingress控制器记录日志:

# metallb
kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.7.3/manifests/metallb.yaml

# nginx
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/baremetal/service-nodeport.yaml

metallb控制器记录:

I0714 22:00:38.056148       7 event.go:258] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"chris-example", Name:"app-ingress", UID:"cbf3b5bf-a67a-11e9-be9a-a4cafa3aa171", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"8681", FieldPath:""}): type: 'Normal' reason: 'UPDATE' Ingress chris-example/app-ingress
I0714 22:01:19.153298       7 event.go:258] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"chris-example", Name:"app-ingress", UID:"cbf3b5bf-a67a-11e9-be9a-a4cafa3aa171", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"8743", FieldPath:""}): type: 'Normal' reason: 'UPDATE' Ingress chris-example/app-ingress
I0714 22:01:38.051694       7 status.go:296] updating Ingress chris-example/app-ingress status from [{192.168.122.253 }] to []
I0714 22:01:38.060044       7 event.go:258] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"chris-example", Name:"app-ingress", UID:"cbf3b5bf-a67a-11e9-be9a-a4cafa3aa171", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"8773", FieldPath:""}): type: 'Normal' reason: 'UPDATE' Ingress chris-example/app-ingress

作为测试,我删除了与metallb相关的deploy + daemonset:

{"caller":"main.go:72","event":"noChange","msg":"service converged, no change","service":"kube-system/kube-dns","ts":"2019-07-14T21:58:39.656725017Z"}
{"caller":"main.go:73","event":"endUpdate","msg":"end of service update","service":"kube-system/kube-dns","ts":"2019-07-14T21:58:39.656741267Z"}
{"caller":"main.go:49","event":"startUpdate","msg":"start of service update","service":"chris-example/app-lb","ts":"2019-07-14T21:58:39.6567588Z"}
{"caller":"main.go:72","event":"noChange","msg":"service converged, no change","service":"chris-example/app-lb","ts":"2019-07-14T21:58:39.656842026Z"}
{"caller":"main.go:73","event":"endUpdate","msg":"end of service update","service":"chris-example/app-lb","ts":"2019-07-14T21:58:39.656873586Z"}

设置了外部IP后,它将再次重置...

1 个答案:

答案 0 :(得分:0)

我很好奇,重新审理了你的案子。我能够正确地公开该服务。

首先:部署自己的NGINX时不需要使用minikube入口插件。如果这样做,则集群中将有2个入口控制器,这会在以后引起混乱。运行:minikube addons disable ingress

旁注:您可以在您的入口分配给192.168.122.253的IP中看到这种混乱,它不在您在192.168.39.160/28中定义的CIDR范围configmap-metallb.yaml中。


您需要将ingress-nginx的服务类型更改为LoadBalancer。您可以通过运行以下命令来做到这一点:

kubectl edit -n ingress-nginx service ingress-nginx

此外,您可以将app-lb服务更改为NodePort,因为它不需要暴露在集群外部-入口控制器将负责。


说明

Ingress开始考虑ConfigMap对象比Service容易。

MetalLB接受您在ConfigMap中提供的配置,并等待IP请求API调用。当它获得一个时,它将提供您指定的CIDR范围的IP。

以类似的方式,入口控制器(在您的情况下为NGINX)采用Ingress对象中描述的配置,并将其用于将流量路由到群集中的所需位置。

然后ingress-nginx服务通过分配的IP暴露在群集之外。

入站流量由入口控制器(NGINX)根据Ingress对象中描述的规则定向到应用程序字体的服务。

Inbound
traffic
   ++     +---------+
   ||     |ConfigMap|
   ||     +--+------+
   ||        |
   ||        | CIDR range to provision
   ||        v
   ||     +--+----------+
   ||     |MetalLB      |               +-------+
   ||     |Load balancer|               |Ingress|
   ||     +-+-----------+               +---+---+
   ||       |                               |
   ||       |  External IP assigned         |Rules described in spec
   ||       |  to service                   |
   ||       v                               v
   ||    +--+--------------------+      +---+------------------+
   ||    |                       |      |  Ingress Controller  |
   |---->+ ingress-nginx service +----->+      (NGINX pod)     |
   +---->|                       +----->+                      |
         +-----------------------+      +----------------------+
                                                    ||
                                                    VV
                                          +-----------------+
                                          | Backend service |
                                          | (app-lb)        |
                                          |                 |
                                          +-----------------+
                                                   ||
                                                   VV
                                          +--------------------+
                                          | Backend pod        |
                                          | (httpbin)          |
                                          |                    |
                                          +--------------------+