<p>I created a nginx ingress using <a href="https://kubernetes.github.io/ingress-nginx/deploy/#quick-start" rel="nofollow noreferrer">this link</a> using docker-desktop.</p>
<pre class="lang-sh prettyprint-override"><code>kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/cloud/deploy.yaml
</code></pre>
<p>My service:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: be-assinaturas
  namespace: apps-space
  labels:
    tier: backend
    app: assinaturas
spec:
  selector:
    matchLabels:
      name: be-assinaturas
      app: assinaturas
  strategy:
    type: Recreate
  replicas: 2
  template:
    metadata:
      name: be-assinaturas
      labels:
        app: assinaturas
        name: be-assinaturas
    spec:
      containers:
        - name: be-assinaturas
          image: jedi31/assinaturas:latest
          imagePullPolicy: Always

---
kind: Service
apiVersion: v1
metadata:
  name: svc-assinaturas
  namespace: apps-space
spec:
  selector:
    name: be-assinaturas
    app: assinaturas
  type: ClusterIP
  ports:
    - name: be-assinaturas-http
      port: 80
      targetPort: 80
</code></pre>
<p>My ingress resource is defined as:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata: 
  name: ingress-be-assinaturas
  namespace: apps-space
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
spec:
  rules:
    - http:
        paths: 
        - path: /assinaturas
          pathType: Prefix
          backend:
            service:              
              name: svc-assinaturas
              port:
                number: 80
</code></pre>
<p>Running a <code>kubectl get services --all-namespaces</code> I get</p>
<pre class="lang-sh prettyprint-override"><code>NAMESPACE       NAME                                 TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
apps-space      svc-assinaturas                      ClusterIP      10.107.188.28    &lt;none&gt;        80/TCP                       12m
default         kubernetes                           ClusterIP      10.96.0.1        &lt;none&gt;        443/TCP                      66d
ingress-nginx   ingress-nginx-controller             LoadBalancer   10.102.238.173   localhost     80:32028/TCP,443:30397/TCP   5h45m
ingress-nginx   ingress-nginx-controller-admission   ClusterIP      10.98.148.190    &lt;none&gt;        443/TCP                      5h45m
kube-system     kube-dns                             ClusterIP      10.96.0.10       &lt;none&gt;        53/UDP,53/TCP,9153/TCP       66d
</code></pre>
<p>If I do a port forward on service, like this:
<code>kubectl port-forward -n apps-space service/svc-assinaturas 5274:80</code></p>
<p>I can acess my app using curl, like this:
<code>curl -v http://localhost:5274/hc/alive</code></p>
<p>and the response is:</p>
<pre class="lang-sh prettyprint-override"><code>*   Trying 127.0.0.1:5274...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 5274 (#0)
&gt; GET /hc/alive HTTP/1.1
&gt; Host: localhost:5274
&gt; User-Agent: curl/7.68.0
&gt; Accept: */*
&gt;
* Mark bundle as not supporting multiuse
&lt; HTTP/1.1 200 OK
&lt; Content-Type: application/json; charset=utf-8
&lt; Date: Mon, 06 Dec 2021 23:22:40 GMT
&lt; Server: Kestrel
&lt; Transfer-Encoding: chunked
&lt;
* Connection #0 to host localhost left intact
{&quot;service&quot;:&quot;Catalogo&quot;,&quot;status&quot;:&quot;Alive&quot;,&quot;version&quot;:&quot;bab4653&quot;}
</code></pre>
<p>But if I try access the service using Ingress, it returns a 404.
<code>curl -v http://localhost/assinaturas/hc/alive</code></p>
<pre class="lang-sh prettyprint-override"><code>*   Trying 127.0.0.1:80...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 80 (#0)
&gt; GET /assinaturas/hc/alive HTTP/1.1
&gt; Host: localhost
&gt; User-Agent: curl/7.68.0
&gt; Accept: */*
&gt;
* Mark bundle as not supporting multiuse
&lt; HTTP/1.1 404 Not Found
&lt; Date: Mon, 06 Dec 2021 23:22:51 GMT
&lt; Content-Length: 0
&lt; Connection: keep-alive
&lt;
* Connection #0 to host localhost left intact
</code></pre>
<p>What I'm doing wrong here?
Why I can acess the service, but the ingress do not find it?</p>

<p>this is because the prefix <code>/assinaturas</code> need to be omitted by an Nginx <strong>rewrite</strong>.. And that's explain why you got 404 (not found):</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata: 
  name: ingress-be-assinaturas
  namespace: apps-space
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /$1 # &lt;- 🔴 rewrite here
spec:
  rules:
    - http:
        paths: 
        - path: /assinaturas/(.*) # &lt;--  🔴 Match the path to be rewritten
          pathType: Prefix
          backend:
            service:              
              name: svc-assinaturas
              port:
                number: 80
</code></pre>
