Is it possible to Create HttpRoute With External Service As Backend?

Hi All,
My consul mesh version: 1.16.x with API Gateway enabled.
I’ve defined a Kubernetes external service (type = ExternalName) namely: external-route that points to external resource.
I’ve created a HttpRoute and attaches it to my internal-api-gateway (under namespace consul) like this:

apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: external-svc
spec:
parentRefs:

  • name: internal-api-gateway
    namespace: consul
    rules:
  • matches:
    • path:
      type: PathPrefix
      value: /api/foo/v1
      backendRefs:
    • kind: Service
      name: external-route
      port: 80

The route accepted, synced but the backend is not found as seen (external-svc is the namespace) but it’s there.

message: ‘external-svc/external-route: backend not found’
observedGeneration: 1
reason: BackendNotFound

I have no issue creating HttpRoute and attaches to the gateway for real service (clusterip). It’s just that the external service that I run into this issue.
I was wondering if it is even supported.
If anyone has had it worked please show me the steps.

Thanks

You should be able to accomplish this by using a MeshService resource (docs) for your backendRef – which points explicitly to a Consul service – rather than a Kubernetes Service, which does a service lookup in Consul based on the metadata from the Kubernetes Service, which doesn’t exist in this case.

The HTTPRoute would then look similar to the one in this guide, omitting the bits about a peer, assuming your external service is registered in the same Consul cluster as your API gateway.

1 Like

Hi Nathan,
Thanks for the great guidance. I’ll read those & give it a try.
Appreciated very much for your help!

Hi Nathan,
Is MeshService resource only available in the latest consul 1.17.x?
I am at 1.16.x and MeshService resource is not available.
Thanks

Hi Nathan,

I’ve found the issue with the document:
The sample from the official doc MeshService Resource Configuration | Consul | HashiCorp Developer shows apiVersion: api-gateway.consul.hashicorp.com/v1alpha1

but when I checked via kubectl api-resources for my cluster it shows: consul.hashicorp.com/v1alpha1
I am good now. Thanks

1 Like

Hi Nathan,
Happy to report that the solution worked. One thing the document didn’t say is that we have to create a Terminating Gateway for the Consul service (catalog service)
Thank you, again for your help!

1 Like

Great to hear! I’ll work on getting that apiVersion corrected. Thanks for pointing this out!

1 Like

Thank you, Nathan!
Happy New Year!

Happy New Year to you as well!