我有两个吊舱,每个都有一个LoadBalancer svc。每个服务的IP地址都正常工作。
我的第一个服务是:
apiVersion: v1
kind: Service
metadata:
name: hello-world-1
spec:
type: LoadBalancer
selector:
greeting: hello
version: one
ports:
- protocol: TCP
port: 60000
targetPort: 50000我的第二个服务是:
apiVersion: v1
kind: Service
metadata:
name: hello-world-2
spec:
type: LoadBalancer
selector:
greeting: hello
version: two
ports:
- protocol: TCP
port: 5000
targetPort: 5000我的入口是:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.class: gce
spec:
defaultBackend:
service:
name: hello-world-1
port:
number: 60000
rules:
- http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: hello-world-1
port:
number: 60000
- path: /v2
pathType: ImplementationSpecific
backend:
service:
name: hello-world-2
port:
number: 5000只有第一条路是这样工作的,当我
<MY_IP>/v2在我得到的url酒吧
Cannot GET /v2如何配置入口,使其在未指定子路径时命中/路由,而当指定/v2路由时则到达/v2路由?
如果我改变第一条路线到
backend:
service:
name: hello-world-2
port:
number: 5000把第二个有效的处理掉。
但是如果我改变到/v2的路线,它就停止工作了?
编辑*
在本教程之后,入口嘟嘟尝试更改yaml,使不同的路由位于不同的端口上,从而破坏了它。有人知道为什么吗?
发布于 2021-10-25 20:30:19
默认情况下,当您在集群中创建入口时,GKE将创建一个HTTP(S)负载均衡器,并将其配置为将流量路由到您的应用程序,如下文1所述。因此,您不应该将服务配置为LoadBalancer类型,而是需要将它们配置为NodePort。
在这里,您可以遵循一个类似于您想要实现的完整实现的示例:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web1
namespace: default
spec:
selector:
matchLabels:
run: web1
template:
metadata:
labels:
run: web1
spec:
containers:
- image: gcr.io/google-samples/hello-app:1.0
imagePullPolicy: IfNotPresent
name: web1
ports:
- containerPort: 8000
protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web2
namespace: default
spec:
selector:
matchLabels:
run: web2
template:
metadata:
labels:
run: web2
spec:
containers:
- image: gcr.io/google-samples/hello-app:2.0
imagePullPolicy: IfNotPresent
name: web2
ports:
- containerPort: 9000
protocol: TCPapiVersion: v1
kind: Service
metadata:
name: web1
namespace: default
spec:
ports:
- port: 8000
protocol: TCP
targetPort: 8080
selector:
run: web1
type: NodePort
---
apiVersion: v1
kind: Service
metadata:
name: web2
namespace: default
spec:
ports:
- port: 9000
protocol: TCP
targetPort: 8080
selector:
run: web2
type: NodePortapiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.class: gce
spec:
defaultBackend:
service:
name: web1
port:
number: 8000
rules:
- http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: web1
port:
number: 8000
- path: /v2
pathType: ImplementationSpecific
backend:
service:
name: web2
port:
number: 9000如果您正确配置了所有内容,那么命令kubectl get - ingress my-ingress的输出应该如下所示:
NAME CLASS HOSTS ADDRESS PORTS AGE
my-ingress <none> * <External IP> 80 149m而且,如果您的服务指向正确的端口,并且应用程序正在侦听这些端口,那么对您的外部ip (curl external )做一个卷曲应该可以将您带到应用程序的第一个版本,下面是我的示例输出:
Hello, world!
Version: 1.0.0
Hostname: web1-xxxxxxxxxxxxxx对您的外部ip /v2 (curl external /v2)做一个卷曲应该可以将您带到您的应用程序的第二版:
Hello, world!
Version: 2.0.0
Hostname: web2-xxxxxxxxxxxxxxhttps://stackoverflow.com/questions/69698545
复制相似问题