<p>I want to use k8s ingress to forward the domain to some service with URI. The ingress yaml just like as below:</p>
<pre><code>- host: foo.example
  http:
    paths:
    - backend:
        path: /
        pathType: Prefix
        service:
          name: serviceA
          port:
            number: 8999
          path: /foo/bar # don't have this attribute, but I want something like this
      
</code></pre>
<p>I found the k8s documents say the <code>path</code> attribute in <code>paths</code> can do this:</p>
<ul>
<li>foo.example/foo -&gt; serviceA:8999</li>
<li>foo.example/bar -&gt; serviceB:9888</li>
</ul>
<p>But I want to do this: <strong>foo.example -&gt; serviceA:8999/foo/bar</strong>. The same thing in nginx config is:</p>
<pre><code>server {
    server_name foo.example;
    location / {
      proxy_pass http://service:8999/foo/bar;
    }
}
</code></pre>
<p>How could I do in the k8s ingress? Thanks.</p>

zzm
<p>Nginx Ingress controller supports rewrites and code snippets. I think what you want can be done by annotations. From the example here <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/examples/rewrite/</a> your code should look like:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /foo/bar/$1
  name: &lt;ingress-name&gt;
  namespace: &lt;namespace&gt;
spec:
  ingressClassName: nginx
  rules:
  - host: fool.example
    http:
      paths:
      - path: /(.*)
        pathType: Prefix
        backend:
          service:
            name: serviceA
            port: 
              number: 8999
</code></pre>
<p>You can add even more complex behavior (like your nginx config) with server snippets:</p>
<p><a href="https://github.com/kubernetes/ingress-nginx/blob/main/docs/user-guide/nginx-configuration/annotations.md#server-snippet" rel="nofollow noreferrer">https://github.com/kubernetes/ingress-nginx/blob/main/docs/user-guide/nginx-configuration/annotations.md#server-snippet</a></p>
