<p>I am trying to set up Traefik as my application's load balancer in Kubernetes. I was able to successfully set it up on Minikube, but things are slightly different in production.</p>
<p>Using some network policies, traffic comes in through our org's PLB, which I want to reach Traefik. Based on rules, it should redirect to the corresponding service.</p>
<p>I can view the Traefik dashboard with the configuration below, but I get <strong>too many redirects</strong> on whoami at abc.com/ms/whoami</p>
<p><strong>Infrastructure:</strong>
Orgs PLB &gt; Traefik LB &gt; Role based routing &gt; Microservice A/B/C...</p>
<p><strong>Part of configurations</strong></p>
<p><em>traefik.yaml</em></p>
<pre class="lang-yaml prettyprint-override"><code>---
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`) &amp;&amp; (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: &quot;org.plb&quot;
spec:
  backend:
    serviceName: traefik
    servicePort: 8080
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: abc.com
  annotations:
    kubernetes.io/ingress.class: &quot;org.plb&quot;
spec:
  backend:
    serviceName: traefik
    servicePort: 80
</code></pre>
<p><strong>whoami.yaml</strong></p>
<pre class="lang-yaml prettyprint-override"><code>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`) &amp;&amp; PathPrefix(`/ms/whoami`)
    kind: Rule
    services:
    - name: whoami
      port: 80
</code></pre>
<p><strong>logs</strong></p>
<pre class="lang-sh prettyprint-override"><code>- - [13/Aug/2020:23:56:09 +0000] &quot;GET /ms/whoami HTTP/1.1&quot; 301 17 &quot;-&quot; &quot;-&quot; 114 &quot;web-to-websecure@internal&quot; &quot;-&quot; 0ms
- - [13/Aug/2020:23:56:09 +0000] &quot;GET /ms/whoami HTTP/1.1&quot; 301 17 &quot;-&quot; &quot;-&quot; 115 &quot;web-to-websecure@internal&quot; &quot;-&quot; 0ms
- - [13/Aug/2020:23:56:09 +0000] &quot;GET /ms/whoami HTTP/1.1&quot; 301 17 &quot;-&quot; &quot;-&quot; 116 &quot;web-to-websecure@internal&quot; &quot;-&quot; 0ms
.....
.....
- - [13/Aug/2020:23:56:09 +0000] &quot;GET /ms/whoami HTTP/1.1&quot; 301 17 &quot;-&quot; &quot;-&quot; 128 &quot;web-to-websecure@internal&quot; &quot;-&quot; 0ms
</code></pre>

<p>I would follow the logs on the client too 🔎. It could be that your whoami application is redirecting from <code>/ms/whoami</code> to <code>/ms/whoami/</code> and then your external load balancer from <code>/ms/whoami/</code> to <code>/ms/whoami</code>.</p>
<p>Or it could be that your application/microservice is redirecting from <code>/ms/whoami</code> to something else like <code>/</code> and then your load balancer is redirecting that back to <code>/ms/whoami</code>.  (You can also try <code>stripprefix-traefik</code> middleware if this is the case)</p>
<p>The above are just examples, as you can see it's evident you have a loop 🤷.</p>
<p>✌️</p>
