I am trying to configure Traefik ingressRoute to route requests from a host to a url. The host and traefik is setup in region1 while the url is for the loadbalancer in region2 pointing to services in region2. See my ingressroute configuration below:
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: route-name
namespace: default
spec:
entryPoints:
- web
routes:
- match: Host(`region1.domain.com`) && PathPrefix(`/`)
kind: Rule
services:
test-service:
loadBalancer:
servers:
- url: http://region2.domain.com/
I tried to follow the example here: https://doc.traefik.io/traefik/routing/services/ but I get the error:
IngressRoute in version "v1alpha1" cannot be handled as a IngressRoute: strict decoding error: unknown field "spec.routes[0].services.test-service"
I am able to access the url for the loadbalancer in region2,so just wondering if it is possible/how to configure the Ingressroute to route request to the url?
If you're looking to route requests from a Traefik IngressRoute in one region to a service or load balancer URL in another region, there are few different ways to achieve this.
option 1
create a Kubernetes Service of type ExternalName
that points to your external URL. This service acts as a DNS alias to your external service.
apiVersion: v1
kind: Service
metadata:
name: external-service
namespace: default
spec:
type: ExternalName
externalName: Yourregion2.domain.com
and update your IngressRoute to route requests to the ExternalName Service you just created.
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: route-name
namespace: default
spec:
entryPoints:
- web
routes:
- match: Host(`yourregion1.domain.com`) && PathPrefix(`/`)
kind: Rule
services:
- name: external-service
port: 80
This configuration assumes that requests to region1.domain.com
will be routed to region2.domain.com
through the external-service
.
The port
should match the port your external service listens on. Since we're pointing to a URL, 80
is used for HTTP, but adjust accordingly if your service uses HTTPS or another port.
Verify your service.
kubectl get svc external-service -n default
Test the routing by accessing region1.domain.com
from a browser or using a tool like curl
. You should be redirected to the service hosted at region2.domain.com
.