<p>using ingress example in kubernetes. I've been trying to browse but couldn't understand how to rewrite ingress to take a file which needs from the website with the ingress object in kubernetes from a folder</p>

<p>Here is the example:</p>

<pre><code> apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /$1
      name: tomcat-ingress
      namespace: default 
    spec:
      rules:
      - host: rewrite.bar.com
        http:
          paths:
          - backend:
              serviceName: tomcat-deployment-service
              servicePort: 8080
            path: /tomcat/?(.*)
          - backend:
              serviceName: nginx-deployment-service
              servicePort: 80
            path: /nginx/?(.*)
</code></pre>

<p>AND here how is done in our local nginx server:</p>

<pre><code>  location ~* /company/logo/[0-9]*/.*\.(jpg|jpeg|gif|png)$ {
                root /opt/comapny/docs-branch/;
                rewrite /company/logo/([0-9]*)/(.*) /$1/$2 break;
</code></pre>

<p>I'm trying to figure out how when accessing this endpoint to redirect to a folder so it can take its file when needed. Also shall it try to access them from the nginx controller pod or the pod that has the service with the ingress</p>

<p>It's possible to add <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-snippet" rel="nofollow noreferrer">custom config snippets to an Ingress via annotations</a>:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/server-snippet: |
      location ~* /company/logo/[0-9]*/.*\.(jpg|jpeg|gif|png)$ {
          rewrite /company/logo/([0-9]*)/(.*) /$1/$2 break;
      }
</code></pre>

<p>You can easily break things here, so to view the eventual config file in the ingress-controller pod:</p>

<pre><code>kubectl get pods
kubectl exec mingress-nginx-ingress-controller-8f57f66d-mm9j7 cat /etc/nginx/nginx.conf | less
</code></pre>
