码迷,mamicode.com
首页 > 其他好文 > 详细

K8S traffic ingress rewrite 规则

时间:2019-11-26 09:17:28      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:ber   问题   不同   authorize   node   习惯   com   targe   lan   

需求如下:

域名 service
www.baidu.com/authorize saas-jcpt-saas-uc-authorize-core-tomcat-online

分析:

1.要到ingress,所以前面不能去掉authorize

2.需要在ingress上配置rewrite

配置

www.baidu.com和saas-jcpt-saas-uc-authorize-core-tomcat-online这两个在不同的命名空间,所以需要在saas-jcpt-tomcat-online下创建一个新的ingress,配置如下:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: public-fe-n-saas-uc-node-online-ingress
namespace: saas-jcpt-tomcat-online
annotations:
traefik.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: www.baidu.com
http:
paths:
- backend:
serviceName: saas-jcpt-saas-uc-authorize-core-tomcat-online
servicePort: 8080
path: /authorize
status:
loadBalancer: {}

注意一个小坑:

如下需求:

域名 service

www.abc.com/aaa/ saas-jcpt-saas-uc-authorize-core-tomcat-online/bbb/

我们习惯的写法可能如下:


apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: public-fe-n-saas-uc-node-online-ingress
  namespace: saas-jcpt-tomcat-online
  annotations:
    traefik.ingress.kubernetes.io/rewrite-target: /bbb/
spec:
  rules:
  - host: www.abc.com
    http:
      paths:
      - backend:
          serviceName: saas-jcpt-saas-uc-authorize-core-tomcat-online
          servicePort: 8080
        path: /aaa/
status:
  loadBalancer: {}

这个时候我们访问http://www.abc.com/aaa/xxx,我们发会现404,容器上抓包发现实际调用的URL为:saas-jcpt-saas-uc-authorize-core-tomcat-online/bbbxxx,中间的/没有了。

同时把path及traefik.ingress.kubernetes.io/rewrite-target最后的/去掉,问题可解决:


apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: public-fe-n-saas-uc-node-online-ingress
  namespace: saas-jcpt-tomcat-online
  annotations:
    traefik.ingress.kubernetes.io/rewrite-target: /bbb
spec:
  rules:
  - host: www.abc.com
    http:
      paths:
      - backend:
          serviceName: saas-jcpt-saas-uc-authorize-core-tomcat-online
          servicePort: 8080
        path: /aaa
status:
  loadBalancer: {}

K8S traffic ingress rewrite 规则

标签:ber   问题   不同   authorize   node   习惯   com   targe   lan   

原文地址:https://blog.51cto.com/8341475/2453333

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!