How does Traefik automatically remove the prefix for backward forwarding?
This article was last updated on: July 24, 2024 am
preface
Traefik is a modern HTTP reverse proxy and load balancer that makes it easy to deploy microservices.
Traefik works with multiple existing infrastructure components (Docker, Swarm patterns, Kubernetes, Marathon, Consul, Etcd, Rancher, Amazon ECS…). Integrate and configure yourself automatically and dynamically.
Series:
In practice, there is often such a demand, the URL entered by the user ishttps://e-whisper.com/alert-manager/#/alerts
, but forwarding to the backend to becomehttp://alertmanager:9093/#/alerts
, How to implement based on Traefik on K8S?
The answer is: use StripPrefixRegex MiddleWare.
Actual combat
Create a MiddleWare directly as follows:
1 |
|
The function implemented above is to remove one layer/<xxx>/
Prefix.
Remove the two layers of prefix
Removing the two layers of prefix is also simple:
1 |
|
IngressRoute uses
Use it directly like this:
1 |
|
🎉🎉🎉 Finish!
EOF