gpt4 book ai didi

Kubernetes 入口路径仅适用于/

转载 作者:行者123 更新时间:2023-12-04 22:55:41 26 4
gpt4 key购买 nike

我已经配置了一个 kubernetes 入口服务,但它只在路径是/

我已经为路径尝试了各种不同的值,包括:

/*
/servicea
/servicea/
/servicea/*

这是我的入口配置(有效)
- apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: boardingservice
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: my.url.com
http:
paths:
- path: /
backend:
serviceName: servicea-nodeport
servicePort: 80

这是我的 nodeport 服务
- apiVersion: v1
kind: Service
metadata:
name: servicea-nodeport
spec:
type: NodePort
ports:
- port: 80
targetPort: 8081
nodePort: 30124
selector:
app: servicea

这是我的部署
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: servicea
spec:
replicas: 1
template:
metadata:
name: ervicea
labels:
app: servicea
spec:
containers:
- image: 350329402011.dkr.ecr.eu-west-2.amazonaws.com/servicea
name: servicea
ports:
- containerPort: 8080
protocol: TCP
- image: 350329402011.dkr.ecr.eu-west-2.amazonaws.com/serviceb
name: serviceab
ports:
- containerPort: 8081
protocol: TCP

如果路径是/那么我可以这样做 http://my.url.com/api/ping
但是因为我将有多个服务,所以我想这样做: http://my.url.com/servicea/api/ping 但是当我将路径设置为/servicea 时,我得到一个 404。

我在 AWS 上使用 ingress-nginx 入口 Controller 运行 kubernetes

任何想法?

最佳答案

您使用的不是 kubernetes Pod,因为它们是要使用的。 A Pod

it contains one or more application containers which are relatively tightly coupled — in a pre-container world, they would have executed on the same physical or virtual machine.



如果您有两个应用程序 serviceaserviceb ,它们应该在不同的 Pod 上运行:一个用于 servicea 的 Pod 和另一个用于 serviceb 的 Pod。这有很多好处:您可以单独部署它们,独立扩展它们等。
作为 docs say

A Pod represents a unit of deployment: a single instance of an application in Kubernetes, which might consist of either a single container or a small number of containers that are tightly coupled and that share resources.



可以使用 Deployments 创建这些 Pod,就像您已经在做的那样。这很好,值得推荐。

运行 Deployments 后,您将创建一个不同的 Service 来平衡给定 Pod 的所有 Deployment 之间的流量。

最后,您希望根据请求 URL 来点击 serviceaserviceb。这可以用 Ingress 来完成,正如你所尝试的那样,但是 mapping each path to different services 。例如
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: my.url.com
http:
paths:
- path: /servicea
backend:
serviceName: servicea
servicePort: 80
- path: /serviceb
backend:
serviceName: serviceb
servicePort: 80

这样,使用/servicea 路径进入入口 Controller 的请求将由 servicea 服务背后的 Pod 提供服务。使用/serviceb 路径进入入口 Controller 的请求将由 serviceb 服务背后的 Pod 提供服务。

关于Kubernetes 入口路径仅适用于/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48283450/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com