<p>I'm new to k8s and trying to get a cluster on GKE set up. I had it working close with just services and nginx built into the frontend image, however the routing was not working correctly, so looking online and its clear I should use an ingress. Been trying to get the nginx-ingress set up, but keep getting a 404 response, and I cannot figure out what I'm doing wrong.</p>
<p>I'm pulling the ingress from here:</p>
<pre><code>kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/cloud/deploy.yaml
</code></pre>
<p>and have the controller yaml set up like so:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    nginx.ingress.kubernetes.io/user-regex: &quot;true&quot;
    nginx.ingress.kuberenetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/enable-cors: &quot;true&quot;
    nginx.ingress.kubernetes.io/cors-allow-origin: &quot;*&quot;
    nginx.ingress.kubernetes.io/cors-allow-methods: &quot;PUT, GET, POST, OPTIONS, DELETE&quot;
    nginx.ingress.kubernetes.io/cors-allow-headers: &quot;DNT,X-CustomHeader,X-LANG,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Api-Key,X-Device-Id,Access-Control-Allow-Origin&quot;
  
spec:
  rules:
  - http:
      paths:
      - path: /?(.*)
        pathType: Prefix
        backend:
          service:
            name: client-service
            port:
              number: 3000
      - path: /api/?(.*)
        pathType: Prefix
        backend:
          service:
            name: server-service
            port:
              number: 5000
  ingressClassName: nginx
</code></pre>
<p>client service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: client-service
spec:
  ports:
    - port: 3000
      protocol: TCP
      targetPort: http-port
  selector:
    app: client
  type: ClusterIP
</code></pre>
<p>client deployment:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: client-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: client
    spec:
      containers:
        - name: client
          image: jowz/client:v4.2
          ports:
            - containerPort: 3000
              name: http-port
  selector:
    matchLabels:
      app: client
</code></pre>
<p>I have no errors, image pull issues, or anything showing either in the terminal or in the GKE console.</p>
<p>pods:</p>
<pre><code>NAMESPACE       NAME                                                 READY   STATUS      RESTARTS   AGE
default         client-deployment-9ccf8cf87-27pvv                    1/1     Running     0          87m
default         mongodb                                              1/1     Running     0          21h
default         server-deployment-df679664f-q9fjw                    1/1     Running     0          87m
ingress-nginx   ingress-nginx-admission-create-tsp4n                 0/1     Completed   0          9m23s
ingress-nginx   ingress-nginx-admission-patch-q7spm                  0/1     Completed   1          9m23s
ingress-nginx   ingress-nginx-controller-86b55bb769-2bqs5            1/1     Running     0          9m24s
kube-system     event-exporter-gke-d4b7ff94-4st8l                    2/2     Running     0          21h
kube-system     fluentbit-gke-xlv7v                                  2/2     Running     0          21h
kube-system     gke-metrics-agent-fhnmq                              2/2     Running     0          21h
kube-system     konnectivity-agent-697c66b96-bvfdw                   1/1     Running     0          21h
kube-system     konnectivity-agent-autoscaler-864fff96c4-n9tlp       1/1     Running     0          21h
kube-system     kube-dns-autoscaler-758c4689b9-7gzx8                 1/1     Running     0          21h
kube-system     kube-dns-fc686db9b-hjl4d                             4/4     Running     0          21h
kube-system     kube-proxy-gke-octodemo-default-pool-20afc590-94qj   1/1     Running     0          21h
kube-system     l7-default-backend-9db4bd868-zgx8s                   1/1     Running     0          21h
kube-system     metrics-server-v0.5.2-66bbcdbffc-bmzp6               2/2     Running     0          21h
kube-system     pdcsi-node-fqzzl                                     2/2     Running     0          21h
</code></pre>
<p>services:</p>
<pre><code>default         client-service                       ClusterIP      10.92.6.30     &lt;none&gt;          3000/TCP                     88m
default         kubernetes                           ClusterIP      10.92.0.1      &lt;none&gt;          443/TCP                      21h
default         mongodb-service                      ClusterIP      10.92.4.232    &lt;none&gt;          27017/TCP                    21h
default         server-service                       ClusterIP      10.92.15.190   &lt;none&gt;          5000/TCP                     88m
ingress-nginx   ingress-nginx-controller             LoadBalancer   10.92.2.242    35.235.98.121   80:30275/TCP,443:30487/TCP   10m
ingress-nginx   ingress-nginx-controller-admission   ClusterIP      10.92.13.144   &lt;none&gt;          443/TCP                      10m
kube-system     default-http-backend                 NodePort       10.92.14.152   &lt;none&gt;          80:30200/TCP                 21h
kube-system     kube-dns                             ClusterIP      10.92.0.10     &lt;none&gt;          53/UDP,53/TCP                21h
kube-system     metrics-server                       ClusterIP      10.92.11.249   &lt;none&gt;          443/TCP                      21h
</code></pre>
<p>Curling gets the same response as the browser:</p>
<pre><code>*   Trying 35.235.98.121:80...
* Connected to 35.235.98.121 (35.235.98.121) port 80 (#0)
&gt; GET / HTTP/1.1
&gt; Host: 35.235.98.121
&gt; User-Agent: curl/7.81.0
&gt; Accept: */*
&gt; 
* Mark bundle as not supporting multiuse
&lt; HTTP/1.1 404 Not Found
&lt; Date: Tue, 18 Jul 2023 21:05:23 GMT
&lt; Content-Type: text/html
&lt; Content-Length: 146
&lt; Connection: keep-alive
&lt; 
&lt;html&gt;
&lt;head&gt;&lt;title&gt;404 Not Found&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;center&gt;&lt;h1&gt;404 Not Found&lt;/h1&gt;&lt;/center&gt;
&lt;hr&gt;&lt;center&gt;nginx&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;
* Connection #0 to host 35.235.98.121 left intact
</code></pre>
<p>but ping returns find:</p>
<pre><code>--- 35.235.98.121 ping statistics ---
43 packets transmitted, 43 received, 0% packet loss, time 42063ms
rtt min/avg/max/mdev = 21.119/36.551/206.584/33.645 ms
</code></pre>
<p>If anyone can see where I'm going wrong, please let me know. Been running in circles trying to wrap my head around this</p>

Jowz
<p>I think the primary problem here is that you've misspelled some of the annotations on your Ingress resource.</p>
<ol>
<li><p>You wrote <code>user</code> where you meant <code>use</code>. Instead of:</p>
<pre><code>nginx.ingress.kubernetes.io/user-regex: &quot;true&quot;
</code></pre>
<p>You need:</p>
<pre><code>nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
</code></pre>
</li>
<li><p>You spelled <code>kubernetes</code> as <code>kuberenetes</code>. Instead of:</p>
<pre><code>nginx.ingress.kuberenetes.io/rewrite-target: /$1
</code></pre>
<p>You need:</p>
<pre><code>nginx.ingress.kubernetes.io/rewrite-target: /$1
</code></pre>
</li>
</ol>
<p>With these two changes, things seem to work as expected. You can see my complete test <a href="https://github.com/larsks/so-example-76716570-nginx-ingress" rel="nofollow noreferrer">here</a>.</p>
