External Services
This page describes how to use Traefik Hub with external Services, for example legacy APIs hosted on VMs (Virtual Machines) or on other systems.
Introduction¶
External Services refer to remote APIs that are located outside a Kubernetes cluster.
Traefik Hub uses the ExternalName Service of Kubernetes to manage APIs which are running outside the Kubernetes cluster, such as VMs or other systems.
More than that, it is possible to use Traefik Hub with ExternalName Services to manage any third party API, follow the external Services tutorial to learn more.
Using an external domain name¶
ExternalName Services don't have selectors, or any defined ports or endpoints, therefore, you can use an ExternalName Service to direct traffic to an external Service.
Using an external domain name service tells the system that the DNS name in the externalName
field (api.apis.guru
) is the location of the resource that backs the service.
When a DNS request is made against the Kubernetes DNS server, it returns the externalName
in a CNAME record, informing the client to look up the returned name to get the IP address.
ExternalName Services are implemented at the DNS level. A CNAME DNS record is created for the service. Therefore, clients connecting to the service will connect to the external service directly.
Configuration¶
Field | Description | Required |
---|---|---|
spec.externalName |
Specifies the location (FQDN) at which that external Service can be reached at, in this case, "api.apis.guru". | Yes |
spec.ports.port |
Specifies the reachable port of the external Service | No |
Examples
---
apiVersion: v1
kind: Service
metadata:
name: api-apis-guru
namespace: traefik
spec:
type: ExternalName
# FQDN of the external API
externalName: api.apis.guru
ports:
- port: 443
---
apiVersion: hub.traefik.io/v1alpha1
kind: APIAccess
metadata:
name: api-apis-guru
namespace: traefik
spec:
groups:
- support
apiSelector:
matchLabels:
app: api-apis-guru
---
apiVersion: hub.traefik.io/v1alpha1
kind: APIGateway
metadata:
name: api-apis-guru
namespace: traefik
spec:
apiAccesses:
- api-apis-guru
---
apiVersion: hub.traefik.io/v1alpha1
kind: APIPortal
metadata:
name: api-apis-guru
namespace: traefik
spec:
title: "External Service api.apis.guru example"
description: "This shows an example about how to use Traefik Hub with an external API."
apiGateway: api-apis-guru
---
apiVersion: v1
kind: Service
metadata:
name: api-apis-guru
namespace: traefik
spec:
type: ExternalName
externalName: api.apis.guru
ports:
- port: 443
---
apiVersion: hub.traefik.io/v1alpha1
kind: API
metadata:
name: api-apis-guru
namespace: traefik
labels:
app: api-apis-guru
spec:
pathPrefix: /demo
service:
name: api-apis-guru
port:
number: 443
openApiSpec:
url: https://raw.githubusercontent.com/APIs-guru/openapi-directory/main/APIs/apis.guru/2.2.0/openapi.yaml
port:
number: 443
What's next¶
- Follow the tutorial about how to manage external Services