在我们的一个域https://www.secretwish.in上-所有404流量都将流向默认的GKE入口,而它必须路由到我的应用程序。
我的应用程序上的所有其他页面运行正常,问题仅在于404页面,所有流量都在gke默认入口上进行。范例网址-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
答案 0 :(得分:0)
在GKE
文档中,您可以找到有关GKE Ingress的信息,对于特定的path
,您应指定backend
,否则将收到问题404 default backend
。
您可以通过在您的控制台中提供后端字段来指定默认后端 入口清单。任何与规则中的路径不匹配的请求 字段发送到后端字段中指定的服务和端口。 ...如果未指定默认后端,则GKE将提供默认 后端返回404。
中
Default backend
将重定向所有找不到的请求 在任何spec.rules.http.paths.path
为了进行一点测试,我使用了2 deployments
和2 services
的{{3}}形式。
选项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
请记住,Ingress on GKE需要大约5-6分钟才能开始正常工作
答案 1 :(得分:0)
不确定我们的解决方案是否适合您。我们还面临类似的问题(不完全是),我们不想更改已部署的入口(即无法添加服务器别名),因此我们采取了一些措施来确保在浏览器/请求中键入的所有主机地址都转换为已配置的地址进入。
在此示例中,我们将在本地/ etc / hosts中创建条目
<actual ingress IP> www.secretwish.in