【问题标题】:Minikube Nginx Ingress not finding service endpointMinikube Nginx Ingress 找不到服务端点
【发布时间】:2021-10-26 09:45:47
【问题描述】:

我在让 Nginx 入口控制器在我的 Minikube 集群中工作时遇到了一些问题。可能是 Ingress 配置中的一些错误,但我无法找出它。

首先,我部署了一个服务,它在没有入口的情况下运行良好。

kind: Service
apiVersion: v1
metadata:
  name: online
  labels:
    app: online
spec:
  selector:
    app: online
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 5001
  type: LoadBalancer

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: online
  labels:
    app: online
spec:
  replicas: 1
  selector:
    matchLabels:
      app: online
  template:
    metadata:
      labels:
        app: online
      annotations:
        dapr.io/enabled: "true"
        dapr.io/app-id: "online"
        dapr.io/app-port: "5001"
        dapr.io/log-level: "debug"
        dapr.io/sidecar-liveness-probe-threshold: "300"
        dapr.io/sidecar-readiness-probe-threshold: "300"
    spec:
      containers:
      - name: online
        image: online:latest
        ports:
        - containerPort: 5001
        env:
        - name: ADDRESS
          value: ":5001"
        - name: DAPR_HTTP_PORT
          value: "8080"
        imagePullPolicy: Never

然后检查它的网址

minikube service online --url
http://192.168.49.2:32323

请求看起来没问题。

curl http://192.168.49.2:32323/userOnline
OK

之后我尝试应用 minikube 提供的 nginx 入口。 我安装了 ingress 并通过引用this 运行了一个示例,一切正常。

最后,我配置了我的 Ingress。

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: online-ingress
  annotations:
spec:
  rules:
    - host: online
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: online
                port:
                  number: 8080

并通过添加行更改 /etc/hosts

192.168.49.2    online

和测试:

curl online/userOnline
502 Bad Gateway

日志是这样的:

192.168.49.1 - - [26/Aug/2021:09:45:56 +0000] "GET /userOnline HTTP/1.1" 502 150 "-" "curl/7.68.0" 80 0.002 [default-online-8080] [] 172.17.0.5:5001, 172.17.0.5:5001, 172.17.0.5:5001 0, 0, 0 0.004, 0.000, 0.000 502, 502, 502 578ea1b1471ac973a2ac45ec4c35d927
2021/08/26 09:45:56 [error] 2514#2514: *426717 upstream prematurely closed connection while reading response header from upstream, client: 192.168.49.1, server: online, request: "GET /userOnline HTTP/1.1", upstream: "http://172.17.0.5:5001/userOnline", host: "online"
2021/08/26 09:45:56 [error] 2514#2514: *426717 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.49.1, server: online, request: "GET /userOnline HTTP/1.1", upstream: "http://172.17.0.5:5001/userOnline", host: "online"
2021/08/26 09:45:56 [error] 2514#2514: *426717 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.49.1, server: online, request: "GET /userOnline HTTP/1.1", upstream: "http://172.17.0.5:5001/userOnline", host: "online"
W0826 09:45:56.918446       7 controller.go:977] Service "default/online" does not have any active Endpoint.
I0826 09:46:21.345177       7 status.go:281] "updating Ingress status" namespace="default" ingress="online-ingress" currentValue=[] newValue=[{IP:192.168.49.2 Hostname: Ports:[]}]
I0826 09:46:21.349078       7 event.go:282] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"online-ingress", UID:"b69e2976-09e9-4cfc-a8e8-7acb51799d6d", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"23100", FieldPath:""}): type: 'Normal' reason: 'Sync' Scheduled for sync

我发现错误与 Ingress 的注释有关。如果我将其更改为:

  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1

错误是:

404 page not found

和日志:

I0826 09:59:21.342251       7 status.go:281] "updating Ingress status" namespace="default" ingress="online-ingress" currentValue=[] newValue=[{IP:192.168.49.2 Hostname: Ports:[]}]
I0826 09:59:21.347860       7 event.go:282] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"online-ingress", UID:"8ba6fe97-315d-4f00-82a6-17132095fab4", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"23760", FieldPath:""}): type: 'Normal' reason: 'Sync' Scheduled for sync
192.168.49.1 - - [26/Aug/2021:09:59:32 +0000] "GET /userOnline HTTP/1.1" 404 19 "-" "curl/7.68.0" 80 0.002 [default-online-8080] [] 172.17.0.5:5001 19 0.000 404 856ddd3224bbe2bde9d7144b857168e0

其他信息。

NAME     TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
online   LoadBalancer   10.111.34.87   <pending>     8080:32323/TCP   6h54m

我上面提到的示例是NodePort 服务,而我的是LoadBalancer,这是最大的区别。但我不知道为什么它对我不起作用。

【问题讨论】:

  • 负载均衡器需要外部 IP。您的外部 IP 处于待处理状态。 Minikube IP 将无助于重定向来自 ingress -> 服务的请求,如果您在那里使用它 LB。您需要 LB IP 才能从入口 -> 服务调用。
  • 以防万一我问哪个driver 用于minikube vm? (可在.minikube/profiles/minikube/config.json查看)。
  • 我找不到相同的图像来测试,所以尝试使用简单的http-https-echo 图像。如果您的服务在/userOnline 上提供服务,那么应该将相同的服务添加到path 中的入口定义中,并且您不需要任何rewrites。让我知道发生什么事。至于第二部分,最终会通过 service 定向到 pod。
  • @tanxin 还有!如果你想在 minikube 中有外部 IP,你需要有一个负载均衡器。由于这被视为metal bare 安装,您可以通过运行minikube addons enable metallb 来启用metal load balancer。请参考metallb
  • @moonkotte,我做到了,您的建议确实有效。它返回 404,因为我拼写错误(usrOnline->userOnline)。谢谢。

标签: nginx kubernetes kubernetes-ingress minikube


【解决方案1】:

将其移出 cmets 使其可见。


入口

主要问题在于入口规则中的path,因为应用程序在online/userOnline 上提供流量。如果请求转到online,则入口返回404

在这种情况下也不需要重写注释。

ingress.yaml 应如下所示:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: online-ingress
#  annotations:
spec:
  rules:
    - host: online
      http:
        paths:
          - path: /userOnline
            pathType: Prefix
            backend:
              service:
                name: online
                port:
                  number: 8080

更多关于ingress的详情


Minikube 上的负载平衡器

由于 minikube 被认为是bare metal 安装,所以要获得external IP 用于服务/入口,需要使用专门设计的metallb 解决方案。

MetalLB 是裸机 Kubernetes 集群的负载均衡器实现,使用标准路由协议。

它作为minikube 的附加组件提供,可以通过以下方式启用:

minikube addons enable metallb

它需要创建一个configMap 并设置。请参考metallb configuration

【讨论】:

    猜你喜欢
    • 2019-05-30
    • 2020-08-05
    • 1970-01-01
    • 2018-02-24
    • 1970-01-01
    • 2021-01-16
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多