Gateway connection to Redis in Kubernetes

Hi @Gabriel_Pu,

If you’re open to using Docker, please check this repo. My colleague created it very recently. It is a stripped-down version of our official Tyk Pro Docker Demo repo, modified to work with a Redis Cluster

You can remove any services you won’t use, like the Dashboard, pump, mongo etc from the docker-compose.

Below is some other info that would be helpful:


In the first step, you’ll need to add 6 Redis nodes in your cluster as individual services that use the Bitnami Redis Cluster images (Im using this because it does all the ‘grunt’ work in the invidual Redis configuration part for us). At the time of writing this, Redis 6 is the latest that is supported by Tyk.

In the file we also initiate the master node first (denoted by 'REDIS_CLUSTER_CREATOR=yes') as you’ll get soft errored out if it’s not in this sequence. We’re also exposing port 6380 in this step so when we have our cluster up and running, we can easily test it in the terminal.

Also really important that each node belongs in to the Tyk network otherwise you’ll get no such host errors in your logs.

Each node also needs to be aware of the other nodes in the system, so we have to add all of the nodes in the environments. In the environment variables, you can also add passwords, empty passwords (as above), or nothing in here at all since for Bitnami images the default password is bitnami. For testing purposes, it’s easier without a password.

Troubleshooting:

Some useful troubleshooting information:

  1. Each Redis node has to be in the same network, ie tyk
  2. Master Redis must be up first before replicas
  3. Need minimum of 6 nodes in the Cluster (3:3)
  4. You can get a racing conditions when you’re standing everything up, i.e Tyk goes up before Redis which will collapse Tyk/ throw errors. It’s best if you up the Redis Cluster before Tyk, this way when Tyk goes up it can just connect to Redis. Assuming you have everything in one Docker-compose.yml file, then you can just restart your Dashboard later. After restarting your Dashboard, everything should be working fine.
  5. All nodes exist in the default port (as opposed to each node being in their own port)
  6. Make sure the Redis version is a version that’s supported by Tyk (otherwise you’ll end up with a lot of unknown errors)
  7. Connect directly to your master node and trying to set a random key value pair, if you get an error then there’s something wrong with your Redis set up. You can connect by either using the Docker exec command or by redis-cli -h localhost -p 6380 . This is why we exposed 6380 earlier in the docker compose file. Once you’re connected you can run the following commands:
  8. keys * - this will list all the keys, if set up properly you should see some Tyk keys.
  9. set a 1 - if there’s something wrong with your Redis nodes, then you’ll see an error similar to this: (error) MOVED 15495 192.178.300.10:6379

Let us know how you get on.

1 Like