APIs from External URLs
External Services refer to remote APIs that are located outside a Kubernetes cluster.
Introduction
Traefik Hub uses the ExternalName Service of Kubernetes to manage APIs which are running outside the Kubernetes cluster, such as VMs or other systems.
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.
Managing external URLs Using CRDs
Field | Description | Required |
---|---|---|
spec.type | The Kubernetes Service type, for example, ExternalName. | Yes |
spec.type.externalName | Specifies the location (FQDN) at which that external Service can be reached at, for example, api.apis.guru. | Yes |
spec.type.ports.port | Specifies the reachable port of the external Service. | No |
Examples
- ExternalName object
- Complete example
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