I am trying to set up a multicluster gateway. We are planning to have many different domains mapped to a single ip. I see that this would be done with URLRewrite with HTTPRoute. I also followed the enabling multicluster documentation. I was using the following documentation: https://cloud.google.com/kubernetes-engine/docs/how-to/deploying-multi-cluster-gateways and https://cloud.google.com/kubernetes-engine/docs/how-to/enabling-multi-cluster-gateways and https://cloud.google.com/kubernetes-engine/docs/how-to/deploying-gateways.
I am able to get a fault filter abort message, but I am not able to get the URLRewrite to work when I curl and it also looks like no redirection occurs according to curl -H Host:<hostname> -H Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8" -w '\n%{url_effective}\n%{num_redirects}\n' <ip>.
Here is yaml for the gateway:
kind: Gateway
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
name: <gateway name>
namespace: <namespace>
spec:
gatewayClassName: gke-l7-global-external-managed-mc
listeners:
- name: http
protocol: HTTP
port: 80
#will error if no certificates given for https so commenting out for now
# - name: https
# protocol: HTTPS
# port: 443
allowedRoutes:
kinds:
- kind: HTTPRoute
addresses:
- type: NamedAddress
value: <name of reserved global static ip>
Here is yaml for the HTTPRoute:
kind: HTTPRoute
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
name: <HTTPRoute name>
namespace: <namespace>
spec:
parentRefs:
- namespace: <namespace>
name: <Gateway name>
sectionName: http
hostnames:
- example.hostname
rules:
- filters:
- type: URLRewrite
urlRewrite:
hostname: example.hostname
backendRefs:
- name: <backend service>
port: 80
The backend service exists, but it is not running, but it doesn't seem to matter if I scale it to run, redirections don't happen according to the curl commands. I was creating the gateway and then waiting before it's healthy before creating the HTTPRoute, but even if I do that the gateway gets this error:
Gateway: Invalid : error cause: no-error-isolation: error getting ServiceImportConfig <backend service>.<namespace>: serviceimportconfigs.net.gke.io "<backend service>.<namespace>" not found ===== Route/<namespace>/<HTTPRoute name>: error cause: no-error-isolation: error getting ServiceImportConfig <backend service>.<namespace>: serviceimportconfigs.net.gke.io "<backend service>.<namespace>" not found
When this happens the associated ip address is removed from the interface, but when I go to the ip I am still able get the fault filter abort message. I don't want to change the config for the backend service for ServiceExport, but as seen from the HTTPRoute yaml I don't have ServiceImport kind for the backendrefs so I don't know why it would be relevant.
Everything is in the same namespace. To reiterate Despite the error and the ip address not listing in the Gateways section in Gateways, Services & Ingress section I am able to get fault filter abort when I go to the ip.
The loadbalancer that seems to have been created is <name of autogenerated loadbalancer>, but when I click on it in the google cloud console I get "Unable to find the resource you requested". I think this occurred even when the gateway was healthy. I don't know why this happens. I tried talking to google support about this before in previous case, but they for some reason said that a loadbalancer like in https://cloud.google.com/load-balancing/docs/https/setting-up-url-rewrite had to be set up and had rules, but this makes no sense as I thought the gateway object was supposed to tell the implementation to make the loadbalancer and to set the rules.
Right now I am not even looking for traffic to be correctly redirected to the backend service, I want to see the redirection or URLRewriting to the right domain to occur.
I want to make sure I understand what you are trying to do:
1) Use a single multi-cluster gateway
2) Map multiple domains / sub-domains to the IP address of that gateway, e.g.
test.example.com
test2.example.com
sample.com
should all route to the GW and then of course to different backends
Is that correct?
1. I believe so.
2. I believe so. Right now I am not so concerned with changing/creating A records for the domains so much as testing with curl and specifying the host to test the gateway routing.
Thanks for the additional info.
A couple of things:
1) I don't think URLRewrite is what you want. URLRewrite rewrites the host header which is sent to the backend service. It does not create a redirect back to the client. It simply rewrites the header that is sent from the gateway to the backend.
2) I think what you actually want is multiple HTTPRoutes, with each HTTPRoute matching a different hostname and then routing to a specific backend.
I am using HTTPRoutes and URLRewrite is a filter as seen with posted yaml. Are you saying if I had hostname1 hostname2 hostname3 all with different backend but same IP I wouldn't need URLRewrite or any rules or filters?
For testing I deleted the HTTPRoute I had and I changed the yaml to the following. The command to apply the yaml wouldn't work without rules field:
kind: HTTPRoute
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
name: <HTTPRoute name>
namespace: <namespace>
spec:
parentRefs:
- namespace: <namespace>
name: <Gateway name>
sectionName: http
hostnames:
- example.hostname
rules:
- backendRefs:
- name: <name of service>
port: 80
I am still seeing fault filter abort and no redirects when I curl -H Host:example.hostname -H Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8" -w '\n%{url_effective}\n%{num_redirects}\n' <ip>.
If you are implying that it won't redirect in such a way that curl could see that and measure it I am at least looking for the fault filter abort message to be gone and some other error instead because I am not able to have the backend service to be running all the time so it is off.