gpt4 book ai didi

kubernetes - Traefik在Ingress中重定向过多

转载 作者:行者123 更新时间:2023-12-02 12:10:42 26 4
gpt4 key购买 nike

我试图在Kubernetes中将Traefik设置为我的应用程序的负载平衡器。我能够在Minikube上成功设置它,但是在生产中情况略有不同。
使用一些网络策略,流量通过我们组织的PLB进入,我想到达Traefik。根据规则,它应该重定向到相应的服务。
我可以使用以下配置查看Traefik仪表板,但我在abc.com/ms/whoami上的whoami上收到了太多的重定向
基础结构:
组织单位PLB> Traefik LB>基于角色的路由>微服务A / B / C ...
部分配置
traefik.yaml

---
apiVersion: v1
kind: Service
metadata:
name: traefik
spec:
type: LoadBalancer
selector:
app: traefik
ports:
- protocol: TCP
port: 80
name: web
targetPort: 80
- protocol: TCP
port: 443
name: websecure
targetPort: 80
- protocol: TCP
port: 8080
name: admin
targetPort: 8080
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: traefik-dashboard
spec:
tls: {}
entryPoints:
- web
- websecure
routes:
- match: Host(`traefik-abc.com`) && (PathPrefix(`/services/traefik`) || PathPrefix(`/api`))
kind: Rule
services:
- name: api@internal
kind: TraefikService
middlewares:
- name: basic-auth
name: stripprefix-traefik
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: traefik-abc.com
annotations:
kubernetes.io/ingress.class: "org.plb"
spec:
backend:
serviceName: traefik
servicePort: 8080
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: abc.com
annotations:
kubernetes.io/ingress.class: "org.plb"
spec:
backend:
serviceName: traefik
servicePort: 80
whoami.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: whoami
labels:
app: whoami
spec:
replicas: 1
selector:
matchLabels:
app: whoami
template:
metadata:
labels:
app: whoami
spec:
containers:
- name: whoami
image: containous/whoami
ports:
- name: web
containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: whoami
spec:
ports:
- protocol: TCP
name: web
port: 80
selector:
app: whoami
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: whoami
spec:
tls: {}
entryPoints:
- web
- websecure
routes:
- match: Host(`abc.com`) && PathPrefix(`/ms/whoami`)
kind: Rule
services:
- name: whoami
port: 80
日志
- - [13/Aug/2020:23:56:09 +0000] "GET /ms/whoami HTTP/1.1" 301 17 "-" "-" 114 "web-to-websecure@internal" "-" 0ms
- - [13/Aug/2020:23:56:09 +0000] "GET /ms/whoami HTTP/1.1" 301 17 "-" "-" 115 "web-to-websecure@internal" "-" 0ms
- - [13/Aug/2020:23:56:09 +0000] "GET /ms/whoami HTTP/1.1" 301 17 "-" "-" 116 "web-to-websecure@internal" "-" 0ms
.....
.....
- - [13/Aug/2020:23:56:09 +0000] "GET /ms/whoami HTTP/1.1" 301 17 "-" "-" 128 "web-to-websecure@internal" "-" 0ms

最佳答案

我也会关注客户端上的日志。可能是您的whoami应用程序从/ms/whoami重定向到/ms/whoami/,然后将外部负载均衡器从/ms/whoami/重定向到/ms/whoami
或者可能是您的应用程序/微服务正在从/ms/whoami重定向到类似/的其他内容,然后您的负载平衡器正在将其重定向回/ms/whoami。 (如果是这种情况,您也可以尝试使用stripprefix-traefik中间件)
上面只是示例,您可以看到很明显您有一个循环🤷。
✌️

关于kubernetes - Traefik在Ingress中重定向过多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63404811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com