指向错误服务的入口路由



我已经从舵图中设置了k3s v1.20.4+k3s1,带有Klipper Lb和nginx ingress 3.24.0。我在关注这篇文章,但我偶然发现了一个非常奇怪的问题,我的入口主机会指向错误的服务。

这是我的配置:

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 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,我只是换成了Metalb,我仍然收到同样的问题

好的,我发现了问题。事实上,它与我之前发布到我的kustomization.yaml配置中的配置无关:

commonLabels:
app: myapp

仅仅移除commonLabels就解决了问题。