Implementing Runtime API Governance in Traefik Hub
In a recent blog post, we discussed the top five policies for runtime API governance. Now, let’s look at how Traefik Hub implements these policies. Traefik Hub is a Kubernetes-native API management solution built with scalability, flexibility, and simplicity in mind. Traefik Hub helps route traffic to services in dynamic, microservices-oriented environments.
In the following sections, we will provide examples of configuration implementation in Traefik Hub to support the standards we have discussed. But note that our examples are not exhaustive - Traefik Hub supports many more capabilities and configuration options!
Policy 1: Use a developer-friendly, traceable, and easy-to-rollback approach for API deployments
As a Kubernetes-native solution, Traefik Hub supports declarative resource configuration. Traefik Hub configuration can be done through Kubernetes resources like Ingress
and Service
, and Traefik Custom Resource Definitions (CRDs) like IngressRoutes
, Middleware
, API
, APIPortal
, APIAccess
, APIVersion
, and APIRateLimit
. Configuration can be version-controlled in Git and automatically applied to the Kubernetes cluster using GitOps tools like ArgoCD and Flux.
For example, defining external traffic routing to a service involves creating an API CRD and exposing the API with an IngressRoute
. The following resource definition declares an API called hello-api, and provides the path to its OpenAPI description.
Next, specify an IngressRoute
CRD with routes to connect incoming requests to services that can handle them. The following resource definition declares a router that matches a request with the host api.example.com
to the hello-api-service.
Developers can save configurations to a Git repository, and GitOps operators ensure that these configurations are consistently applied across environments. The diagram below illustrates this process.
The declarative nature of Traefik configuration, combined with GitOps workflows, supports advanced and progressive deployment capabilities. Teams can follow blue-green deployments and canary releases using GitOps operators like ArgoCD and FluxCD. If any issues are detected, changes can be rolled back to a stable version by reverting the changes in the Git repository.
TIP: For an in-depth treatment on how to do load-balancing in Traefik and support advanced deployment techniques, see Traefik’s Advanced Load Balancing course.
Policy 2: Make comprehensive and correct API documentation available to users
Traefik Hub API management includes an API Developer Portal to make API documentation accessible to developers and other API users. In the portal, users can explore available API endpoints, understand their usage, and test them in real time.
The APIPortal
CRD creates and configures the portal, generating a web interface for browsing the API documentation. The visibility of API documentation depends on user groups. An API will be visible to an API consumer if they belong to a specified group with access to the API, as configured by the APIAccess CRD.
You can create an API developer portal by applying an APIPortal resource as follows:
To expose the portal, create an IngressRoute
resource, as demonstrated below:
Policy 3: Secure all API traffic from malicious and unauthorized access
With Traefik Hub, you can ensure secure API access using protocols such as Oauth2, OpenID Connect (OIDC), API keys, and JSON Web Tokens (JWTs). Additionally, Traefik integrates with identity providers such as Keycloak and Okta. Traefik also integrates with any other IdP that supports the OIDC protocol to handle user identities and authorize access to the APIs and API portals.
To protect APIs from DDoS attacks or excessive requests from a single client, you can implement rate limits by defining an APIRateLimit resource. Traefik allows you to do this for all APIs or specific user groups. The following declarative config defines a rate limit of 100 requests per minute.