Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

K8S traffic ingress rewrite rule

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

The requirements are as follows:

Domain name service

Www.baidu.com/authorize saas-jcpt-saas-uc-authorize-core-tomcat-online

Analysis:

1. To get to ingress, so you can't remove authorize from the front.

two。 Rewrite needs to be configured on ingress

Configuration

Www.baidu.com and saas-jcpt-saas-uc-authorize-core-tomcat-online are in different namespaces, so you need to create a new ingress under saas-jcpt-tomcat-online, configured as follows:

ApiVersion: extensions/v1beta1kind: Ingressmetadata:name: public-fe-n-saas-uc-node-online-ingressnamespace: saas-jcpt-tomcat-onlineannotations:traefik.ingress.kubernetes.io/rewrite-target: / spec:rules:- host: www.baidu.comhttp:paths:- backend:serviceName: saas-jcpt-saas-uc-authorize-core-tomcat-onlineservicePort: 8080path: / authorizestatus:loadBalancer: {}

Pay attention to a small pit:

The following requirements are required:

Domain name service

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

The way we are used to writing may be as follows:

ApiVersion: extensions/v1beta1kind: Ingressmetadata: 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: {}

At this time, when we visit http://www.abc.com/aaa/xxx, we will find that the actual URL called on the container is: saas-jcpt-saas-uc-authorize-core-tomcat-online/bbbxxx, the middle / none.

The problem can be solved by removing the last of path and traefik.ingress.kubernetes.io/rewrite-target at the same time:

ApiVersion: extensions/v1beta1kind: Ingressmetadata: name: public-fe-n-saas-uc-node-online-ingress namespace: saas-jcpt-tomcat-online annotations: traefik.ingress.kubernetes.io/rewrite-target: / bbbspec: rules:-host: www.abc.com http: paths:-backend: serviceName: saas-jcpt-saas-uc-authorize-core-tomcat-online servicePort: 8080 path: / aaastatus: loadBalancer: {}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report