具有多个后端服务的 GKE Ingress 返回 404
我正在尝试创建一个 GKE Ingress,它根据路径指向两个不同的后端服务。我看到一些帖子解释说这只能通过 nginx Ingress 实现,因为 gke ingress 不支持重写目标。不过,此 Google 文档 GKE Ingress - 多个后端服务 ,似乎另有暗示。我已按照文档中的步骤进行操作,但没有取得任何成功。仅返回路径前缀 /
上可用的服务。任何其他路径前缀(例如 /v2
)都会返回 404 Not found。
我的设置详细信息如下。这里有一个明显的错误吗——Google 文档是否不正确,这只能使用 nginx 入口实现?
-- Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ingress
annotations:
kubernetes.io/ingress.global-static-ip-name: app-static-ip
networking.gke.io/managed-certificates: app-managed-cert
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: api-service
port:
number: 80
- path: /v2
pathType: Prefix
backend:
service:
name: api-2-service
port:
number: 8080
-- Service 1
apiVersion: v1
kind: Service
metadata:
name: api-service
labels:
app: api
spec:
type: NodePort
selector:
app: api
ports:
- port: 80
targetPort: 5000
-- Service 2
apiVersion: v1
kind: Service
metadata:
name: api-2-service
labels:
app: api-2
spec:
type: NodePort
selector:
app: api-2
ports:
- port: 8080
targetPort: 5000
I'm trying to create a GKE Ingress that points to two different backend services based on path. I've seen a few posts explaining this is only possible with an nginx Ingress because gke ingress doesn't support rewrite-target. However, this Google documentation, GKE Ingresss - Multiple backend services, seems to imply otherwise. I've followed the steps in the docs but haven't had any success. Only the service that is available on the path prefix of /
is returned. Any other path prefix, like /v2
, returns a 404 Not found.
Details of my setup are below. Is there an obvious error here -- is the Google documentation incorrect and this is only possible using nginx ingress?
-- Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ingress
annotations:
kubernetes.io/ingress.global-static-ip-name: app-static-ip
networking.gke.io/managed-certificates: app-managed-cert
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: api-service
port:
number: 80
- path: /v2
pathType: Prefix
backend:
service:
name: api-2-service
port:
number: 8080
-- Service 1
apiVersion: v1
kind: Service
metadata:
name: api-service
labels:
app: api
spec:
type: NodePort
selector:
app: api
ports:
- port: 80
targetPort: 5000
-- Service 2
apiVersion: v1
kind: Service
metadata:
name: api-2-service
labels:
app: api-2
spec:
type: NodePort
selector:
app: api-2
ports:
- port: 8080
targetPort: 5000
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GCP Ingress 支持多路径。 使用 Ingress 设置 HTTP(S) 负载平衡中也对此进行了详细描述。在我的测试中,我使用了 Hello-world v1 和 v2。
有3个可能的问题。
问题也可能是由
防火墙
配置引起的。确保您有正确的设置。 (一般来说,在新集群中我不需要添加任何内容,但如果您有更多内容并且具有特定的防火墙配置,它可能会阻止)。port
、containerPort
和targetPort
之间配置错误。下面是我的示例:
第一次部署
第二次部署
入口
输出:
请记住,您还可以使用<通过添加特定注释在 GKE 上使用 code>Nginx Ingress。
人们在
GKE
上使用nginx ingress
的主要原因是使用rewrite
注释以及使用ClusterIP
或的可能性NodePort
作为服务类型,其中GCP ingress
仅允许NodePort
服务类型。您可以在GKE Ingress for HTTP(S) 负载平衡
GCP Ingress supports multiple paths. This is also well described in Setting up HTTP(S) Load Balancing with Ingress. For my test I've used both Hello-world v1 and v2.
There are 3 possible issues.
Issue might be also caused by the
Firewall
configuration. Make sure you have proper settings. (In general, in the new cluster I didn't need to add anything but if you have more stuff and have specific Firewall configurations it might block).Misconfiguration between
port
,containerPort
andtargetPort
.Below my example:
1st deployment with
2nd deployment
Ingress
Outputs:
Please keep in mind that you can also use
Nginx Ingress
on GKE by adding specific annotation.Main reason why people use
nginx ingress
onGKE
is usingrewrite
annotation and possibility to useClusterIP
orNodePort
as serviceType, whereGCP ingress
allows onlyNodePort
serviceType.Additional information you can find in GKE Ingress for HTTP(S) Load Balancing