# Tyk

import { Tabs, TabsContent, TabsList, TabsTrigger } from "zudoku/ui/Tabs"

{/* vale off */}
{/* THIS FILE WAS AUTOGENERATED FROM THE PUBLIC EXAMPLE REPOSITORY. DO NOT EDIT THIS FILE DIRECTLY. */}


This example uses [`Tyk`](https://tyk.io/), 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 CLI.
   Use the [unikraft CLI](/cli/unikraft) or the legacy [kraft CLI](https://unikraft.org/docs/cli/install).
   You need a [BuildKit](https://github.com/moby/buildkit) builder. The easiest way to get one is via [Docker](https://docs.docker.com/engine/install/).
   Alternatively, you can also directly set up and use BuildKit, see the [quick start](https://github.com/moby/buildkit#quick-start).

   :::note
   The unikraft CLI is the current standard, while kraft is the legacy version.
   Choose one of the CLIs below and only run the commands associated with it for the rest of this guide.
   :::

2. Clone the [`examples` repository](https://github.com/unikraft-cloud/examples) and `cd` into the `examples/tyk/` directory:

```bash
git clone https://github.com/unikraft-cloud/examples
cd examples/tyk/
```

Make sure to log into Unikraft Cloud and pick a [metro](/platform/metros) close to you.
This guide uses `fra` (Frankfurt, 🇩🇪):

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft login
```

```bash title="kraft"
# Set Unikraft Cloud access token
export UKC_TOKEN=token
# Set metro to Frankfurt, DE
export UKC_METRO=fra
```

</CodeTabs>

## Build and deploy the Redis instance (used internally by Tyk):

The `REDIS_PASSWORD` environment variable sets the Redis `requirepass` directive.
If not provided, it defaults to `unikraft`.

```bash title="unikraft"
unikraft build ./redis --output <my-org>/redis:latest
unikraft run --scale-to-zero policy=idle,cooldown-time=1000,stateful=true --metro fra -m 256M --image <my-org>/redis:latest --domain tyk-redis.internal -e REDIS_PASSWORD=unikraft
```

Make sure to replace `<my-org>` with your username / org-name in the unikraft CLI commands above.

The output shows the Redis instance details:

```ansi title="unikraft"
metro:           fra
name:            redis-6vgvc
uuid:            63b86d17-06ca-4f95-b921-56e5b3245554
state:           [92mstarting[0m
image:           <my-org>/redis
resources:
  memory:        256MiB
  vcpus:         1
service:
  name:          snowy-water-wivk1i4r
  uuid:          6612de91-d639-4b5a-95d1-b7ae6e91e3c1
  domains:
  - fqdn:        tyk-redis.internal
networks:
- uuid:          19e4b80a-9501-448d-99a6-ec3f7b90805e
  private-ip:    10.0.0.29
  mac:           12:b0:0a:00:01:49
timestamps:
  created:       just now
scale-to-zero:
  enabled:       true
  policy:        idle
  stateful:      true
  cooldown-time: 1s
```

or

```bash title="kraft"
kraft cloud deploy --scale-to-zero idle --scale-to-zero-stateful --scale-to-zero-cooldown 1s -M 256Mi --domain tyk-redis.internal --env REDIS_PASSWORD=unikraft ./redis/
```

The output shows the Redis instance details:

```ansi title="kraft"
[90m[[0m[92m●[0m[90m][0m Deployed successfully!
 [90m│[0m
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mname[0m: redis-6vgvc
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90muuid[0m: 63b86d17-06ca-4f95-b921-56e5b3245554
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mmetro[0m: https://api.fra.unikraft.cloud/v1
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mstate[0m: [92mstarting[0m
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mdomain[0m: tyk-redis.internal
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mimage[0m: oci://unikraft.io/<my-org>/redis@sha256:933b8b7714924eb2de880e0f32792698b14a13c83d5aee0f52dddcab5c97099d
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mmemory[0m: 256 MiB
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mservice[0m: snowy-water-wivk1i4r
 [90m├[0m[90m─[0m [90mprivate fqdn[0m: redis-6vgvc.internal
 [90m└[0m[90m─[0m[90m─[0m[90m─[0m [90mprivate ip[0m: 10.0.0.29
```

## Build and deploy the Tyk instance:

```bash title="unikraft"
unikraft build ./tyk --output <my-org>/tyk:latest
unikraft run --scale-to-zero policy=on,cooldown-time=1000 --metro fra -p 443:8080/tls+http -m 256M --image <my-org>/tyk:latest
```

Make sure to replace `<my-org>` with your username / org-name in the unikraft CLI commands above.

The output shows the Tyk instance details:

```ansi title="unikraft"
metro:        fra
name:         tyk-s9ixd
uuid:         4e8a5e56-2d0b-4ca4-88b4-aa816129a66d
state:        [92mstarting[0m
image:        <my-org>/tyk
resources:
  memory:     256MiB
  vcpus:      1
service:
  name:       icy-haze-8ph4u8cz
  uuid:       89079646-353a-4a19-99ac-5498c7d626ad
  domains:
  - fqdn:     icy-haze-8ph4u8cz.fra.unikraft.app
networks:
- uuid:       8085804f-0fe0-4847-ad6e-8518edba126e
  private-ip: 10.0.0.1
  mac:        12:b0:0a:00:0e:b1
timestamps:
  created:    just now
```

or

```bash title="kraft"
kraft cloud deploy --scale-to-zero on --scale-to-zero-cooldown 1s -p 443:8080/tls+http -M 256Mi ./tyk/
```

The output shows the Tyk instance details:

```ansi title="kraft"
[90m[[0m[92m●[0m[90m][0m Deployed successfully!
 [90m│[0m
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mname[0m: tyk-s9ixd
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90muuid[0m: 4e8a5e56-2d0b-4ca4-88b4-aa816129a66d
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mmetro[0m: https://api.fra.unikraft.cloud/v1
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mstate[0m: [92mstarting[0m
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mdomain[0m: https://icy-haze-8ph4u8cz.fra.unikraft.app
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mimage[0m: oci://unikraft.io/<my-org>/tyk@sha256:4954033ada90f980f279e5d825dd7971111a429578ce38be764893ba0d1f358d
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mmemory[0m: 256 MiB
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mservice[0m: icy-haze-8ph4u8cz
 [90m├[0m[90m─[0m [90mprivate fqdn[0m: tyk-s9ixd.internal
 [90m└[0m[90m─[0m[90m─[0m[90m─[0m [90mprivate ip[0m: 10.0.0.1
```

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:

```bash
curl https://icy-haze-8ph4u8cz.fra.unikraft.app/hello
```

```text
{"status":"pass","version":"v5.3.0-dev","description":"Tyk GW","details":{"redis":{"status":"pass","componentType":"datastore","time":"2026-05-25T12:26:07Z"}}}
```

You can list information about the instances by running:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft instances list
```

```bash title="kraft"
kraft cloud instance list
```

</CodeTabs>

<CodeTabs syncKey="cli">

```ansi title="unikraft"
[1mMETRO[0m  [1mNAME[0m         [1mSTATE[0m   [1mIMAGE[0m           [1mMEMORY[0m  [1mVCPUS[0m  [1mFQDN[0m                                  [1mCREATED[0m
fra    tyk-s9ixd    [92mstandby <my-org>/tyk[0m    256MiB  1      icy-haze-8ph4u8cz.fra.unikraft.app    just now
fra    redis-6vgvc  [92mrunning <my-org>/redis[0m  256MiB  1      tyk-redis.internal                    1 minute ago
```

```ansi title="kraft"
[1mNAME[0m         [1mFQDN[0m                                        [1mSTATE[0m    [1mSTATUS[0m      [1mIMAGE[0m                                             [1mMEMORY[0m   [1mVCPUS[0m  [1mARGS[0m  [1mBOOT TIME[0m
tyk-s9ixd    icy-haze-8ph4u8cz.fra.unikraft.app          [94mstandby[0m  standby     oci://unikraft.io/<my-org>/tyk@sha256:4954033...  256 MiB  1            158.32 ms
redis-6vgvc  tyk-redis.internal                          [92mrunning[0m  since 1min  oci://unikraft.io/<my-org>/redis@sha256:933b8...  256 MiB  1            1811.99 ms
```

</CodeTabs>

When done, you can remove the instances:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft instances delete redis-6vgvc tyk-s9ixd
```

```bash title="kraft"
kraft cloud instance remove redis-6vgvc tyk-s9ixd
```

</CodeTabs>

## Customize your app

To customize the Tyk app, you can update:

* `Kraftfile`: the Unikraft Cloud specification
* `Dockerfile` / `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:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft --help
```

```bash title="kraft"
kraft cloud --help
```

</CodeTabs>

Or visit the [CLI Reference](/cli/unikraft) or the [legacy CLI Reference](/cli/kraft/overview).
{/* vale on */}
