I have an API gateway installed in an EKS cluster and I have this communication flow:
User -> F5 LB -> Nginx Ingress Controller LB (devapi.example.com) -> Service -> API Gateway Pods
Right now I am accessing APIs directly through ingress controller load balancer by using the DNS name devapi.example.com and an application path. My ingress template matches the hostname (which is unique and shared for all APIs) and forwards the appended path in the URL to the application pod like this so it can reach the correct API:
https://devapi.example.com/hello-world -> https://api-gateway-service/hello-world
What I need
I want to start publishing applications with a different DNS name for each one in F5. I can publish DNS names in F5 and point them to devapi.example.com (don't really know if I can append a path here). I would like to publish application DNSs in F5 so I can have a DNS name for each application which would redirect to devapi.example.com appending an specific path based on origin DNS:
hello-world-dev.example.com -> devapi.example.com/hello-world
liveness-check-dev.example.com -> devapi.example.com/health
Some hostnames might not match any word in the path (see the liveness-check-dev hostname). Is there any way to map the origin hostnames from F5 with application paths so I can rewrite my paths?
You may consider this approach where you define the F5 configuration:
Create virtual servers where you establish one virtual server (vs_all_apps) on F5 to handle all incoming traffic. Set
devapi.example.comas the default server to handle requests that don't match specific application DNS rules. Then enable SNI server (Server Name Indication) support to differentiate requests based on hostanames.Define iRules, where im pleting an iRule(
rule\_rewrite\_paths)to perform origin-based path rewriting using SNI information. Then extract the hostname from the SNI field usingHTTP::header exists "Host"and[HTTP::host split "." 1]. Create a lookup table (ltm rule lookup table my\_app\_mappings)to map F5 hostnames todevapi.example.compaths. Use thelookupcommand to find the corresponding path based on the extracted hostname, handling cases where there's no direct match. Rewrite the request URI usingHTTP::uriwith the mapped path( [ltm rule lookup table my\_app\_mappings $hostname]:$uri).