【发布时间】:2021-03-20 10:18:31
【问题描述】:
我已经设置了 k3s v1.20.4+k3s1 与 Klipper Lb 和来自 helm 图表的 nginx ingress 3.24.0。 我正在关注this article,但我偶然发现了一个非常奇怪的问题,即我的入口主机会指向错误的服务。
这是我的配置:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-routing
spec:
rules:
- host: echo1.stage.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: echo1
port:
number: 80
- host: echo2.stage.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: echo2
port:
number: 80
---
apiVersion: v1
kind: Service
metadata:
name: echo1
spec:
ports:
- port: 80
targetPort: 5678
selector:
app: echo1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: echo1
spec:
selector:
matchLabels:
app: echo1
replicas: 2
template:
metadata:
labels:
app: echo1
spec:
containers:
- name: echo1
image: hashicorp/http-echo
args:
- "-text=This is echo1"
ports:
- containerPort: 5678
---
apiVersion: v1
kind: Service
metadata:
name: echo2
spec:
ports:
- port: 80
targetPort: 5678
selector:
app: echo2
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: echo2
spec:
selector:
matchLabels:
app: echo2
replicas: 1
template:
metadata:
labels:
app: echo2
spec:
containers:
- name: echo2
image: hashicorp/http-echo
args:
- "-text=This is the new (echo2)"
ports:
- containerPort: 5678
还有我的 Cloudflare DNS 记录(未激活 DNS 代理):
;; A Records
api.stage.example.com. 1 IN A 162.15.166.240
echo1.stage.example.com. 1 IN A 162.15.166.240
echo2.stage.example.com. 1 IN A 162.15.166.240
但是当我多次在 echo1.stage.example.com 上进行 curl 时,我得到的结果如下:
$ curl echo1.stage.example.com
This is echo1
$ curl echo1.stage.example.com
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>
$ curl echo1.stage.example.com
This is the new (echo2)
有时我得到一个错误的网关,有时我得到指向分配给echo2.stage.example.com 的服务的echo1.stage.example.com 域。这是因为LB吗?还是我的配置不好?谢谢!
编辑:它不是来自 LB,我只是切换到 metallb,但我仍然遇到同样的问题
【问题讨论】:
-
您的配置文件完全没问题。我在我的本地种类集群中检查了它们。
-
我认为您的 dns 无法正确解析,这就是您面临 502 bad gateway 错误的原因。
-
@PulakKantiBhowmick 对 502 没问题,但我如何解释有时使用错误服务的事实? :( 你的同类集群是否也有同样的行为?
-
它在我的本地集群中运行良好。我没有发现任何问题。
-
能否在您的 dns 记录中添加完整的域?
标签: kubernetes kubernetes-ingress k3s