kubernetes - K8S Ingress 是否提供任何后端目标路径以及端口?
问题描述
我有两个 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
推荐阅读
- git - How to see if git binary is built against openssl or gnutls when git-http-fetch is not installed?
- python - multiple WS-I filters on NNMi 10.20 SOAP
- android - 将 ArrayAdapter 与 LiveData 一起使用。
- python - 无法访问pixel_array属性pydicom
- javascript - Setting location of Angular production JavaScript bundles in index.html
- java - 使用 JsonIgnoreProperties 特定属性反序列化属性只存在于 JSON
- if-statement - 使用 -> 分配变量而不是检查真值
- html - Bootstrap4 Navbar - 间距元素(右、中、左)
- .net - 12c 连接丢失了一些时间
- express - 将已经存在的模型传递给 Loopback 中的下一个模型