在GKE-Kubernetes上使用"默认后端-404"响应的网站 [英] Website responding with "default backend - 404" on GKE - Kubernetes

查看:21
本文介绍了在GKE-Kubernetes上使用"默认后端-404"响应的网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的一个域https://www.secretwish.in上-所有404流量都将到达默认的GKE入口,而它必须路由到我的应用程序。

我的应用程序上的所有其他页面都工作得很好,问题只是404页面,所有流量都在GKE默认入口上进行。示例URL-https://www.secretwish.in/hshshs

我需要为此找到解决方案,以便所有流量都开始路由到我的应用

群集版本-1.14.10-gke.27

入口文件如下所示:-

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

推荐答案

GKE文档中可以找到关于GKE Ingress的信息,具体的path要指定backend,否则会收到问题404 default backend

您可以通过在中提供后端字段来指定默认后端 入境货单。与规则中的路径不匹配的任何请求 字段发送到后端字段中指定的服务和端口。 ..。如果您没有指定默认后端,GKE会提供一个默认后端 返回404的后端。

Default backend将重定向所有找不到的请求 在任何spec.rules.http.paths.path

对于小测试,我使用了2deployments和2services表单this gke example

选项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 

选项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

请记住,GKE上的Inress大约需要5-6分钟才能正常工作

这篇关于在GKE-Kubernetes上使用"默认后端-404"响应的网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆