API Gateways: Tyk
An API gateway is the entry point to your services, handling authentication, routing, rate-limiting, and observability at the edge of your infrastructure. API traffic fluctuates, so a gateway that scales to zero when idle and starts in milliseconds when traffic returns keeps your API edge ready without paying for it overnight.
This example uses Tyk, an API gateway and management platform.
Tyk is used together with Redis to store API tokens and OAuth clients.
To run this example, follow these steps:
-
Install the unikraft CLI. You need a BuildKit builder. The easiest way to get one is via Docker. Alternatively, you can also directly set up and use BuildKit, see the quick start.
-
Clone the
examplesrepository andcdinto theexamples/tyk/directory:Code
Make sure to log into Unikraft Cloud and pick a metro close to you.
This guide uses fra (Frankfurt, 🇩🇪):
Code
Redis
The REDIS_PASSWORD environment variable sets the Redis requirepass directive.
If not provided, it defaults to unikraft.
Build and deploy the Redis instance (used internally by Tyk):
Code
Make sure to replace <my-org> with your username / org-name in the unikraft CLI commands above.
The output shows the Redis instance details:
Code
Tyk
Build and deploy the Tyk instance.
Set TYK_GW_STORAGE_HOST to the same internal domain you assigned to the Redis instance (tyk-redis.internal in this guide).
If TYK_GW_STORAGE_HOST is unset, Tyk tries to connect to a Redis instance at tyk-redis.internal by default.
Code
Make sure to replace <my-org> with your username / org-name in the unikraft CLI commands above.
The output shows the Tyk instance details:
Code
In this case, the instance names are redis-6vgvc and tyk-s9ixd, and the Tyk address is https://icy-haze-8ph4u8cz.fra.unikraft.app.
They're different for each run.
Use curl to query the Tyk instance on Unikraft Cloud:
Code
Code
You can list information about the instances by running:
Code
Code
When done, you can remove the instances:
Code
Customize your app
To customize the Tyk app, you can update:
Kraftfile: the Unikraft Cloud specificationDockerfile/rootfs/: the Tyk filesystem (in this case the configuration file/etc/tyk.conf)
It's unlikely you will have to update the Kraftfile specification.
Update the contents of the rootfs/etc/tyk.conf file for a different configuration.
You can also update the Dockerfile in order to extend the Tyk filesystem with extra data files or configuration files.
Learn more
Use the --help option for detailed information on using Unikraft Cloud:
Code
Or visit the CLI Reference.