我有两个Web应用程序在同一个码头运行。
如果我只是点击 ip:port,那么它会带来 UI 应用程序,并通过上下文路径带来另一个 REST 应用程序。
以下是配置:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="war">./webapps/my-ui.war</Set>
</Configure>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/api</Set>
<Set name="war">./webapps/my-rest-api.war</Set>
</Configure>
是否有任何选项可以在入口中提供目标路径?
从 Kubernetes 文档中,这是一个入口示例:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
servicePort: 80
您可以根据需要添加任意数量的规则,以将路径映射到正确的服务和端口,在您的情况下,您可以拥有这样的入口:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: app-ingress
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: ui-service
servicePort: 80
- http:
paths:
- path: /api
backend:
serviceName: rest-api-service
servicePort: 80
我不清楚它是如何工作的,但下面的代码对我有用。两个上下文路径如何指向相同的服务和相同的端口,这有点令人困惑。
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: app-ingress
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: common-service
servicePort: 80
- http:
paths:
- path: /api
backend:
serviceName: common-service
servicePort: 80