Ingress - 如何使用基本 URL 进行调度?
Ingress - How to dispath with base URLs?
我有两个名为 svc1
和 svc2
的服务。我可以让入口分派具有不同基本 URL 的相同域到每个服务,即:
ingress.domain/svc1/path-here
-> svc1 获取此请求,路径重写为 /path-here
ingress.domain/svc2/path-here
-> svc2 获取此请求,路径重写为 /path-here
所以我可以为这个 k8s 实例上的所有服务使用一个域吗?
你可以这样做
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
cert-manager.io/cluster-issuer: public-dev
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/proxy-body-size: 50m
nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
nginx.ingress.kubernetes.io/rewrite-target: /
name: public-ingress
spec:
rules:
- host: developer.example.com
http:
paths:
- backend:
serviceName: test-service
servicePort: 80
path: /test-service(/|$)(.*)
- backend:
serviceName: test-service-2
servicePort: 80
path: /test-service-2(/|$)(.*)
tls:
- hosts:
- developer.example.com
secretName: public-dev
我有两个名为 svc1
和 svc2
的服务。我可以让入口分派具有不同基本 URL 的相同域到每个服务,即:
ingress.domain/svc1/path-here
-> svc1 获取此请求,路径重写为 /path-here
ingress.domain/svc2/path-here
-> svc2 获取此请求,路径重写为 /path-here
所以我可以为这个 k8s 实例上的所有服务使用一个域吗?
你可以这样做
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
cert-manager.io/cluster-issuer: public-dev
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/proxy-body-size: 50m
nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
nginx.ingress.kubernetes.io/rewrite-target: /
name: public-ingress
spec:
rules:
- host: developer.example.com
http:
paths:
- backend:
serviceName: test-service
servicePort: 80
path: /test-service(/|$)(.*)
- backend:
serviceName: test-service-2
servicePort: 80
path: /test-service-2(/|$)(.*)
tls:
- hosts:
- developer.example.com
secretName: public-dev