<p>I have a Service which have the following paths (as example):</p>
<ul>
<li>/api/Private1</li>
<li>/api/Private2</li>
<li>/api/Private3</li>
<li>/api/Public1</li>
<li>/api/Public2</li>
</ul>
<p>Is it possible to only expose /api/Public1 and /api/Public2?</p>
<p>So far, the only thing that worked for me is below, but I'm not sure if it is the proper approach:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: dev
  name: txc-dev-public-exposition
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /api/Public1
spec:
  ingressClassName: nginx
  rules:
  - host: messaging-dev.myapp.com
    http:
      paths:
      - path: /gateway/api/Public1
        pathType: Prefix
        backend:
          service:
            name: gatewayapi-svc
            port:
              number: 80
</code></pre>
<p>If I call <a href="https://messaging-dev.myapp.com/api/Public1" rel="nofollow noreferrer">https://messaging-dev.myapp.com/api/Public1</a>, it routes properly. But how to handle query parameters, etc?</p>
<p>Is it possible to do above?</p>
<p>Thank you</p>

Water
<p>You can use regular expression in the path:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: dev
  name: txc-dev-public-exposition
  annotations:
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /api/Public$1
spec:
  ingressClassName: nginx
  rules:
  - host: messaging-dev.myapp.com
    http:
      paths:
      - path: /gateway/api/Public(.*)
        pathType: Prefix
        backend:
          service:
            name: gatewayapi-svc
            port:
              number: 80
</code></pre>
<p><code>$1</code> in the rewrite path is substituted with the capture group <code>(.*)</code> from the path.</p>
