我有两个名称为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: /$2
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