到不同业务的入口路由和到同一业务的不同路径



我有以下入口配置:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
pathType: Exact
backend:
serviceName: web-service
servicePort: 5000
paths:
- path: /api/tasks/.*
pathType: Prefix
backend:
serviceName: tasks-service
servicePort: 5004
paths:
- path: /api/.*
pathType: Prefix
backend:
serviceName: um-service
servicePort: 5001

我打算默认加载前端,然后使用其他路径加载其他服务。我想获得/api/tasks/total_count的总任务数,并从/api/tasks/raise中提出新任务。同时,我想使用/api/auth/login/登录,并查看使用um-service服务的/api/users/list的其他用户。上面的配置只返回最后一个服务(um-service)的默认路径。如何配置默认情况下web加载,然后/api/auth/login/api/users/list被路由到um-service,/api/tasks/也被路由到任务服务?请建议

如果我没理解错的话,你是想达到那个结果:

$ curl <MY_DOMAIN>/api/auth/login
um-service
$ curl <MY_DOMAIN>/api/users/list
um-service
$ curl <MY_DOMAIN>/api/tasks/
tasks-service
$ curl <MY_DOMAIN>/
web-service

你几乎都做对了,但是paths应该只给一次


apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: web-service
servicePort: 5000
- path: /api/tasks/.*
backend:
serviceName: tasks-service
servicePort: 5004
- path: /api/.*
backend:
serviceName: um-service
servicePort: 5001

相关内容

  • 没有找到相关文章

最新更新