Skip to content

External Services

This tutorial explains how to manage a remote API, which is located (hosted) outside your Kubernetes cluster.


Introduction

In this tutorial, you'll learn how to create an external Service to manage an API which is hosted remote, outside your Kubernetes cluster.

An external Service could be a legacy API which is running outside the Kubernetes cluster, for example in a VM (Virtual Machine) which you want to manage with Traefik Hub.

You will use APIS.GURU as an example of an external API. You will learn how to use CRDs for setting up the API, the Service, setting up the API access and the API Portal.


Before you begin

Before getting started, make sure that you're familiar with:

Kubernetes Objects

Objects are sort of like blueprints.

They provide detailed instructions to Kubernetes on how the applications must be set up and managed.

The following YAML file has all CRD Objects and Service definitions needed to deploy a Service to connect Traefik Hub to an external API.


1. Download the example file

Download the YAML file and save it as api-guru.yaml.

---
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 example using api.apis.guru"
  description: "This shows an example about how to manage 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

2. Deploy

In this step, you will use kubectl to apply the api-guru.yaml to your Kubernetes cluster.

kubectl apply -f api-guru.yaml

This will create and configure a new Service (api-apis-guru) on your cluster, including a Portal, API access, etc.


3. Settings overview

The API will be reachable under /demo and will be connected to the new Portal api-apis-guru.

API Guru overview

Guru API overview in Traefik Hub

Consumers which are part of the group support have access to the API.

API Guru Portal overview

Guru Portal overview

4. Access the API Portal

Connect to the Portal for the API.

API Guru Web Portal overview

Guru Web Portal

Run a test request against the API.

API Guru test request

Example request

Summary

In this tutorial, you learned how to connect and manage an external API with Traefik Hub via CRDs.


What's next