Deploy 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:
-
Install the
kraft
CLI tool and a container runtime engine, e.g. Docker. -
Clone the
examples
repository andcd
into theexamples/tyk/
directory:
git clone https://github.com/kraftcloud/examplescd 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:
# Set KraftCloud access tokenexport UKC_TOKEN=token# Set metro to Frankfurt, DEexport UKC_METRO=fra0
When done, invoke the following command to deploy this application on KraftCloud:
kraft cloud compose up
The output shows the Compose output:
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:
kraft cloud compose ps
NAME FQDN STATE STATUS IMAGE MEMORY ARGS BOOT TIMEtyk-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 mstyk-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:
curl https://funky-pond-45usfkxx.fra0-test.kraft.host/hello
{"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:
kraft cloud compose down
Customize your Application
To customize the Tyk application, you can update:
Kraftfile
: the KraftCloud specificationDockerfile
/rootfs/
: the Tyk filesystem (in this case the configuration file/etc/tyk.conf
)compose.yaml
: the Compose specification
spec: v0.6
runtime: tyk:latest
rootfs: ./Dockerfile
cmd: ["/usr/bin/tyk", "start", "--conf", "/etc/tyk.conf"]
FROM scratch
COPY ./rootfs /
{ "listen_address": "", "listen_port": 8080, "secret": "352d20ee67be67f6340b4c0605b044b7", "template_path": "/tyk/templates", "use_db_app_configs": false, "app_path": "/opt/tyk-gateway/apps", "middleware_path": "/opt/tyk-gateway/middleware", "storage": { "type": "redis", "host": "tyk-redis.internal", "port": 6379, "username": "", "password": "", "database": 0, "optimisation_max_idle": 2000, "optimisation_max_active": 4000 }, "enable_analytics": false, "analytics_config": { "type": "", "ignored_ips": [] }, "dns_cache": { "enabled": false, "ttl": 3600, "check_interval": 60 }, "allow_master_keys": false, "policies": { "policy_source": "file" }, "hash_keys": true, "hash_key_function": "murmur64", "suppress_redis_signal_reload": false, "force_global_session_lifetime": false, "max_idle_connections_per_host": 500}
services:
tyk: build: . ports: - 443:8080
redis: image: redis:latest mem_reservation: 512M networks: tyk-network:
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:
kraft cloud --help
Or visit the CLI Reference.