Minikube Nginx Ingress 找不到服务端点

您所在的位置:网站首页 default_page_url改不了 Minikube Nginx Ingress 找不到服务端点

Minikube Nginx Ingress 找不到服务端点

2023-03-22 17:20| 来源: 网络整理| 查看: 265

回答问题

我在让 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并运行了一个示例,一切正常。

最后,我配置了我的 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 8080:32323/TCP 6h54m

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

Answers

将其从评论中移出,使其可见。

入口

主要问题在于入口规则中的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

有关入口的更多详细信息

Minikube 上的负载均衡器

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

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

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

minikube addons enable metallb

它需要创建一个带有设置的configMap。请参考metallb配置



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3