<p>This is my first time using Docker, Kubernetes, Ingress and Skaffold. I'm following along with a online course, but I'm stuck.</p>
<p>When I call just the home path <code>/</code> it returns a response, but any other path that I try returns 404.</p>
<p>The first step I took was to add a custom local development url in /etc/hosts/ so in that file I've added <code>127.0.0.1 ticketing.com</code>.</p>
<p>Then I have my ingress file. I set <code>host</code> to  match ticketing.com and the path uses a regex to match any path after <code>/api/users</code></p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
spec:
  rules:
    - host: ticketing.com
      http:
        paths:
          - path: /api/users/?(.*)
            pathType: Prefix
            backend:
              service:
                name: auth-srv
                port:
                  number: 3000
</code></pre>
<p>This is the file that has the deploy and service yaml for what is going to be an authentication service. In the second part, it looks like the <code>metadata: name</code> matches  <code>auth-srv</code> correctly and <code>port 3000</code> correctly.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: auth
  template:
    metadata:
      labels:
        app: auth
    spec:
      containers:
        - name: auth
          image: lmsankey/auth
---
apiVersion: v1
kind: Service
metadata:
  name: auth-srv
spec:
  selector:
    app: auth
  ports:
    - name: auth
      protocol: TCP
      port: 3000
      targetPort: 3000

</code></pre>
<p>If this helps, here is index.ts with the route.</p>
<pre><code>import express from &quot;express&quot;;
import { json } from &quot;body-parser&quot;;

const app = express();
app.use(json());

app.get(&quot;/api/users/currentuser&quot;, (req, res) =&gt; {
  res.send(&quot;Hi there!&quot;);
});

app.listen(3000, () =&gt; {
  console.log(&quot;Listening on port 3000!!!!!!!!&quot;);
});
</code></pre>
<p>I tried following this answer <a href="https://stackoverflow.com/a/52029100/3692615">https://stackoverflow.com/a/52029100/3692615</a> but honestly I'm not sure I understood entirely, or if that's what I need.</p>
<p>Basically it says to add this line to annotations. <code>nginx.ingress.kubernetes.io/rewrite-target: /</code></p>
<p>Maybe someone more experienced can spot whats going on or point me in the right direction?</p>
<p>Thanks.</p>

Louis Sankey
<p>using your configuration and going to:</p>
<p><a href="http://ticketing.com/api/users/currentuser" rel="nofollow noreferrer">http://ticketing.com/api/users/currentuser</a></p>
<p>i got the message (Hi, there!) and it seems to be fine and correct.</p>
<p>Anyway, i will ask you: &quot;what if you want to add another route on your express app?&quot;</p>
<p>For example, what if you add this lines on your index.ts?</p>
<pre class="lang-js prettyprint-override"><code>app.get('/health', (req, res) =&gt; {               
  res.send(&quot;Hi, i'm fine!&quot;);         
});                               
                                  
app.get('/super-secret-section', (req, res) =&gt; {
  res.send(&quot;shh! this is a supersecret section&quot;); 
});    
</code></pre>
<p>With your current ingress yaml file, adding these lines on your .ts file, implicates that if you want to reach them through ingress, you need to modify your ingress.yaml file to map these two new resources: no good for your aim and overcomplicates the file (if i understood you needs)</p>
<p>Instead, you should consider to use ingress with the prefix (since you want to use pathType: Prefix), then use it adding a prefix for you app (the svc, actually).</p>
<p>Something like this:</p>
<p><code>yourdomain.com/STARTINGPOINTPREFIX/any_path_on_your_app_you_want_add</code></p>
<p>To successfully achieve this goal, you can use a combination of paths and grouping within annotations.</p>
<p>Here, a simple basic example:</p>
<pre class="lang-yaml prettyprint-override"><code>
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx    
    nginx.ingress.kubernetes.io/rewrite-target: /$2 # this line use the group
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot; 
spec:
  rules:
    - http:
        paths:
          - pathType: Prefix
            path: /cool-app(/|$)(.*) # this intercept all the paths of your app using the 'cool-app' prefix
            backend:
              service:
                name: auth-srv
                port:
                  number: 3000
      host: ticketing.com 
</code></pre>
<p>when you apply this ingress yaml, you can reach your app with:</p>
<p><code>http://ticketing.com/cool-app/api/users/currentuser</code></p>
<p>also, if you add the two lines on .ts mentioned above:</p>
<p><code>http://ticketing.com/cool-app/health</code></p>
<p><code>http://ticketing.com/cool-app/super-secret-section</code></p>
<p>In this way, you separate the path of your app, from the ingress route.</p>
<p>From my point of view, the key point to get the ingress, is that you should use it to create, that i call &quot;entry point slices&quot; for your services.</p>
<p>More details on nginx annotation and rewrite
<a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/examples/rewrite/</a></p>
<p>Hope it helps.</p>
