GKE ingress resource returns 404 although it is connected to a service

10/24/2021

I added a default nginx-ingress deployment with a regional IP that I got from GCP.

helm install nginx-ingress \
             nginx-stable/nginx-ingress \
             --set rbac.create=true \
             --set controller.service.loadBalancerIP="<GCP Regional IP>"

I have a dockerized node app with a single .js file. Which I deployed with a basic helm chart. The service is called node-app-blue-helm-chart

const http = require('http');

const hostname = '0.0.0.0';
const port = 80;

const server = http.createServer((req, res) => {
    if (req.url == '/another-page'){
        res.statusCode = 200;
            res.setHeader('Content-Type', 'text/html');
                res.end('<h1>another page</h1>');

    } else {
        res.statusCode = 200;
            res.setHeader('Content-Type', 'text/html');
                res.end('<h1>Hello World</h1>');
    }
});

server.listen(port, hostname, () => {
    console.log('Server running at http://%s:%s/', hostname, port);
});

process.on('SIGINT', function() {
    console.log('Caught interrupt signal and will exit');
    process.exit();
});

I deployed following ingress resource:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-resource
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - host: "*.example.com"
    http:
      paths:
      - path: /*
        pathType: Prefix
        backend:
          service:
            name: node-app-blue-helm-chart
            port:
              number: 80

Although ingress resource acquires IP and endpoint. It still returns 404 error. What can be wrong? Can host: "*.example.com" section be a problem?

More info:

kubectl describe ing ingress-resource
Name:             ingress-resource
Namespace:        default
Address:          <GCP Regional IP>
Default backend:  default-http-backend:80 (10.0.0.2:8080)
Rules:
  Host           Path  Backends
  ----           ----  --------
  *.example.com  
                 /*   node-app-blue-helm-chart:80 (10.0.0.15:80)
Annotations:     kubernetes.io/ingress.class: nginx
                 nginx.ingress.kubernetes.io/ssl-redirect: false
Events:          <none>


kubectl describe svc node-app-blue-helm-chart
Name:              node-app-blue-helm-chart
Namespace:         default
Labels:            app.kubernetes.io/instance=node-app-blue
                   app.kubernetes.io/managed-by=Helm
                   app.kubernetes.io/name=helm-chart
                   app.kubernetes.io/version=1.16.0
                   helm.sh/chart=helm-chart-0.1.0
Annotations:       meta.helm.sh/release-name: node-app-blue
                   meta.helm.sh/release-namespace: default
Selector:          app.kubernetes.io/instance=node-app-blue,app.kubernetes.io/name=helm-chart
Type:              ClusterIP
IP Families:       <none>
IP:                10.3.248.13
IPs:               10.3.248.13
Port:              http  80/TCP
TargetPort:        80/TCP
Endpoints:         10.0.0.15:80
Session Affinity:  None
Events:            <none>

What I tried:

Removing from / in ingress resource. Didn't fix the issue.

kubectl describe ing ingress-resource
Name:             ingress-resource
Namespace:        default
Address:          W.X.Y.Z
Default backend:  default-http-backend:80 (10.0.0.2:8080)
Rules:
  Host           Path  Backends
  ----           ----  --------
  *.example.com  
                 /   node-app-blue-helm-chart:80 (10.0.0.15:80)
Annotations:     kubernetes.io/ingress.class: nginx
                 nginx.ingress.kubernetes.io/ssl-redirect: false
Events:
  Type    Reason          Age        From                      Message
  ----    ------          ----       ----                      -------
  Normal  AddedOrUpdated  <invalid>  nginx-ingress-controller  Configuration for default/ingress-resource was added or updated
-- bcan
google-kubernetes-engine
kubernetes
kubernetes-helm
kubernetes-ingress
nginx-ingress

1 Answer

10/24/2021

Try to edit your Ingress. You have set a path=/*, which may not be what you meant to do. A / should do:

[...]
spec:
  rules:
  - host: "*.example.com"
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: node-app-blue-helm-chart
            port:
              number: 80
-- SYN
Source: StackOverflow