Zudoku
Guides

Tyk

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:

  1. Install the kraft CLI tool and a container runtime engine, e.g. Docker.

  2. Clone the examples repository and cd into the examples/tyk/ directory:

TerminalCode
git clone https://github.com/kraftcloud/examples cd examples/tyk/

Make sure to log into KraftCloud by setting your token and a metro close to you. We use fra0 (Frankfurt, 🇩🇪) in this guide:

TerminalCode
# Set KraftCloud access token export UKC_TOKEN=token # Set metro to Frankfurt, DE export UKC_METRO=fra0

When done, invoke the following command to deploy this application on KraftCloud:

TerminalCode
kraft cloud compose up

The output shows the Compose output:

Code
i building service=tyk i packaging service=tyk [+] building rootfs... done! [+] packaging index.unikraft.io/tyk-tyk... done! [+] pushing index.unikraft.io/tyk-tyk:latest (kraftcloud/x86_64)... done! i creating instance image=redis:latest i no ports or service specified, disabling scale to zero i creating instance image=index.unikraft.io/tyk-tyk@sha256:06f8ba3f2350e57717bd947f43f04a1ac44ab65010c8994488223eb042c30feb i no ports or service specified, disabling scale to zero i starting 2 instance(s)

To list information about the instances, use:

TerminalCode
kraft cloud compose ps
Code
NAME FQDN STATE STATUS IMAGE MEMORY ARGS BOOT TIME tyk-tyk funky-pond-45usfkxx.fra0-test.kraft.host running since 45secs tyk-tyk@sha256:06f8ba3... 128 MiB /usr/bin/tyk start --conf /etc/tyk.conf 38.12 ms tyk-redis running since 45secs redis@sha256:d4604c6d80e7d57590f2c46659f2... 512 MiB /usr/bin/redis-server /etc/redis/redis.conf 18.69 ms

The Tyk and Redis instances are named tyk-tyk and tyk-redis (as defined in the compose.yaml file). Only the Tyk instance is available as a public service. Its URL is https://funky-pond-45usfkxx.fra0-test.kraft.host. It is different for each run.

Use curl to query the Tyk instance on KraftCloud on the available URL:

TerminalCode
curl https://funky-pond-45usfkxx.fra0-test.kraft.host/hello
Code
{"status":"pass","version":"v5.3.0-dev","description":"Tyk GW","details":{"redis":{"status":"pass","componentType":"datastore","time":"2024-07-12T05:57:44Z"}}}

When done, you can bring down the instances:

TerminalCode
kraft cloud compose down

Customize your Application

To customize the Tyk application, you can update:

  • Kraftfile: the KraftCloud specification
  • Dockerfile / rootfs/: the Tyk filesystem (in this case the configuration file /etc/tyk.conf)
  • compose.yaml: the Compose specification

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 additional data files or configuration files.

The compose.yaml file can be update to assign different names, ports, network names or other Compose-specific configurations.

Learn More

Use the --help option for detailed information on using KraftCloud:

TerminalCode
kraft cloud --help

Or visit the CLI Reference.

Last modified on