GKE 入口资源 returns 404 尽管它已连接到服务

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

我使用从 GCP 获得的区域 IP 添加了默认 nginx-ingress 部署。

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

我有一个带有单个 .js 文件的 dockerized 节点应用程序。我用一个基本的掌舵图部署了它。该服务名为 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();
});

我部署了以下入口资源:

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

尽管入口资源获取 IP 和端点。它仍然是 returns 404 错误。有什么问题? host: "*.example.com" 部分会不会有问题?

更多信息:

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>

我尝试了什么:

正在从入口资源中的 /* 中删除 *。没有解决问题。

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

尝试编辑您的 Ingress。您设置了 path=/*,这可能不是您想要的。 / 应该做:

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