<p>I have two apps (workloads): <code>app1</code> and <code>app2</code>. My goal is to redirect trafic from <code>app1</code> to <code>app2</code> if there is the <code>diona</code> prefix. For example:</p>
<pre><code>app1/diona &gt; app2/&lt;api&gt;
</code></pre>
<p>Now I have such rules:</p>
<pre><code>rules:
  - host: host
    http:
      paths:
      - backend:
          serviceName: ingress-37ce1ad1e8214375784d1e50805c056c
          servicePort: 80
        path: /diona
</code></pre>
<p>When I check <code>app1/diona</code> endpoint in logs of <code>app2</code> there is an error:</p>
<pre><code>Not Found: /diona
</code></pre>
<p>How can I redirect trafic correctly without realizing <code>diona</code> prefix in <code>app2</code>?</p>

Альберт Александров
<p>You can achieve it using nginx ingress controller. You code will look like this</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: rewrite
spec:
  rules:
    - host: host
      http:
        paths:
        - backend:
            serviceName: ingress-37ce1ad1e8214375784d1e50805c056c
            servicePort: 80
          path: /diona
</code></pre>
<p>If you want to redirect <code>app1/diona/*</code> to <code>app2/*</code>, change annotations to</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
  name: rewrite
spec:
  rules:
    - host: host
      http:
        paths:
        - backend:
            serviceName: ingress-37ce1ad1e8214375784d1e50805c056c
            servicePort: 80
          path: /diona/(.*)
</code></pre>
<p><a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/" rel="nofollow noreferrer">Reference</a></p>
