简体   繁体   English

网站在 GKE 上以“默认后端 - 404”响应 - Kubernetes

[英]Website responding with “default backend - 404” on GKE - Kubernetes

On one of our domains https://www.secretwish.in - all the 404 traffic is going to the default GKE Ingress whereas it has to route to my application.在我们的一个域https://www.secretwish.in上 - 所有 404 流量都将流向默认的 GKE 入口,而它必须路由到我的应用程序。

All other pages on my application are working fine, the problem is just with 404 page, all traffic is going on gke default ingress.我的应用程序上的所有其他页面都工作正常,问题只是 404 页面,所有流量都在 gke 默认入口上。 Sample URL - https://www.secretwish.in/hshshs样品 URL - https://www.secretwish.in/hshshs

Need to find a solution for this so that all traffic starts routing to my app需要为此找到解决方案,以便所有流量开始路由到我的应用程序

Cluster Version - 1.14.10-gke.27集群版本 - 1.14.10-gke.27

The ingress file looks like:-入口文件如下所示:-

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ans-commerce-ingress
  annotations:
    kubernetes.io/tls-acme: "true"
    kubernetes.io/ingress.class: "nginx"
    ingress.kubernetes.io/tls-minimum-version: "1.0"
spec:
  tls:      
  - hosts:
    - www.secretwish.in
    secretName: www-secretwish-in-tls    

   - host: www.secretwish.in
     http:
       paths:
       - path: /
         backend:
           serviceName: ans-commerce
           servicePort: 80

In GKE docs you can find information regarding GKE Ingress , that for specific path you should specify backend , otherwise you will received issue 404 default backend .GKE文档中,您可以找到有关GKE Ingress的信息,对于特定path ,您应该指定backend ,否则您将收到问题404 default backend

You can specify a default backend by providing a backend field in your Ingress manifest.您可以通过在 Ingress 清单中提供 backend 字段来指定默认后端。 Any requests that don't match the paths in the rules field are sent to the Service and port specified in the backend field.任何与规则字段中的路径不匹配的请求都将发送到后端字段中指定的服务和端口。 ... If you don't specify a default backend, GKE provides a default backend that returns 404. ...如果您不指定默认后端,GKE 会提供返回 404 的默认后端。

Default backend will redirect all request which could not be found in any spec.rules.http.paths.path Default backend将重定向在任何spec.rules.http.paths.path中找不到的所有请求

For little test I've used 2 deployments and 2 services form this gke example .对于小测试,我在这个 gke 示例中使用了 2 个deployments和 2 个services

Option 1 without configured default end选项 1未配置default end

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
  - http:
      paths:
      - path: /world
        backend:
          serviceName: hello-world
          servicePort: 60000
      - path: /kube
        backend:
          serviceName: hello-kubernetes
          servicePort: 80

user@cloudshell:~ (prjoect-name)$ curl 35.244.197.176
default backend - 404
user@cloudshell:~ (prjoect-name)$ curl 35.244.197.176/kube
Hello Kubernetes!
user@cloudshell:~ (prjoect-name)$ curl 35.244.197.176/world
Hello, world!
Version: 2.0.0
Hostname: hello-world-deployment-7f67f479f5-vqzxg
user@cloudshell:~ (prjoect-name)$ curl 35.244.197.176/yvgbhuij
default backend - 404 

Option 2 With defailt backend选项 2使用默认后端

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: my-ingress
spec:
  backend:
    serviceName: hello-world
    servicePort: 60000
  rules:
  - http:
      paths:
      - path: /world
        backend:
          serviceName: hello-world
          servicePort: 60000
      - path: /kube
        backend:
          serviceName: hello-kubernetes
          servicePort: 80

user@cloudshell:~ (prjoect-name)$ curl 35.244.186.95
Hello, world!
Version: 2.0.0
Hostname: hello-world-deployment-7f67f479f5-vqzxg
user@cloudshell:~ (prjoect-name)$ curl 35.244.186.95/hello
Hello, world!
Version: 2.0.0
Hostname: hello-world-deployment-7f67f479f5-kd6fg
user@cloudshell:~ (prjoect-name)$ curl 35.244.186.95/kube
Hello Kubernetes!
user@cloudshell:~ (prjoect-name)$ curl 35.244.186.95/fyvgbhujnkl
Hello, world!
Version: 2.0.0
Hostname: hello-world-deployment-7f67f479f5-vqzxg

Please keep in mind that Ingress on GKE needs about 5-6 minutes before it starts working properly请记住,GKE 上的 Ingress 需要大约 5-6 分钟才能开始正常工作

Not sure our solution applies in you case.不确定我们的解决方案是否适用于您的情况。 We also faced similar issue(not exact), we didn't want to change the deployed ingress(ie can't add server-alias) So we some how made sure that all host address typed in browser/request translates to what is configured in ingress.我们也遇到了类似的问题(不准确),我们不想更改部署的入口(即无法添加服务器别名)所以我们如何确保在浏览器/请求中键入的所有主机地址都转换为配置的内容在入口。

In this example, we would have created entry in local /etc/hosts在此示例中,我们将在本地 /etc/hosts 中创建条目

<actual ingress IP> www.secretwish.in

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM