Traefik在Ingress中重定向过多

时间:2020-08-14 00:11:29

标签: kubernetes traefik traefik-ingress

我试图在Kubernetes中将Traefik设置为我的应用程序的负载平衡器。我能够在Minikube上成功设置它,但是在生产中情况略有不同。

使用一些网络策略,流量通过我们组织的PLB进入,我想到达Traefik。根据规则,它应该重定向到相应的服务。

我可以使用以下配置查看Traefik仪表板,但在abc.com/ms/whoami上的whoami上获得的重定向过多

基础结构: Orgs 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

1 个答案:

答案 0 :(得分:1)

我也将遵循客户端上的日志。可能是您的whoami应用程序从/ms/whoami重定向到/ms/whoami/,然后您的外部负载均衡器从/ms/whoami/重定向到/ms/whoami

也可能是您的应用程序/微服务正在从/ms/whoami重定向到/之类的东西,然后您的负载均衡器正在将其重定向回/ms/whoami。 (在这种情况下,您也可以尝试stripprefix-traefik中间件)

以上仅是示例,您可以看到显然有一个循环

✌️<​​/ p>