How to configure Tyk to work with Redis Sentinels?

Hi,

I want to setup 2 Tyk Opensource Gateways with Redis Sentinels.

For Redis Sentinels, I already formed it, and the failover will happen when Redis master is down, as shown in the following diagram:

Now I put Tyk Opensource Gateway-1 at the machine where Redis master is, and Tyk Opensource Gateway-2 at the machine where Redis replica is, as shown at the following diagram:

Up to now, the Gateways work fine.

However, I noticed one strange behavior on Tyk when I crated (post) an API. Basically I use Tyk API (post) to create an API at Tyk Gateway-1. From the machine where Tyk Gateway-1, I can call that API. However, at the machine Tyk Gateway-2, I cannot call the created API, and got not found message.

Isn’t it when I create an API at Tyk Gateway-1, I should be able to get the same API at Tyk gateway-2? Since they share the same Redis master?

I have done some verification at the Redis sentinel. When I created one key-value at Redis master, I can found that key-value at Redis replica.

I referred to Tyk documentation for the configuration for Tyk with Redis Sentinels:
Configure Redis Sentinel (tyk.io)

At Tyk-Gateway-1, this is the configuration file:

{
“log_level”: “info” ,
“listen_port”: 8080,
“secret”: “352d20ee67be67f6340b4c0605b044b7”,
“template_path”: “/opt/tyk-gateway/templates”,
“tyk_js_path”: “/opt/tyk-gateway/js/tyk.js”,
“middleware_path”: “/opt/tyk-gateway/middleware”,
“use_db_app_configs”: false,
“app_path”: “/opt/tyk-gateway/apps/”,
“storage”: {
“type”: “redis”,
“addrs”:[
“xx.xx.xx.xx:26379”,
“xx.xx.xx.xx:26380”,
“xx.xx.xx.xx:26381”
],
“master_name”:“mymaster”,
“username”: “”,
“password”: “redis_pwd”,
“database”: 0,
“optimisation_max_idle”: 2000,
“optimisation_max_active”: 4000
},
“enable_analytics”: false,
“analytics_config”: {
“type”: “”,
“ignored_ips”:
},
“health_check”: {
“enable_health_checks”: false,
“health_check_value_timeouts”: 60
},
“optimisations_use_async_session_write”: false,
“enable_non_transactional_rate_limiter”: true,
“enable_sentinel_rate_limiter”: false,
“enable_redis_rolling_limiter”: false,
“allow_master_keys”: false,
“policies”: {
“policy_source”: “file”,
“policy_record_name”: “/opt/tyk-gateway/policies/policies.json”
},
“hash_keys”: true,
“close_connections”: false,
“http_server_options”: {
“enable_websockets”: true
},
“allow_insecure_configs”: true,
“coprocess_options”: {
“enable_coprocess”: true,
“coprocess_grpc_server”: “”
},
“enable_bundle_downloader”: true,
“bundle_base_url”: “”,
“global_session_lifetime”: 100,
“force_global_session_lifetime”: false,
“max_idle_connections_per_host”: 500,
“enable_jsvm”: true
}

At Tyk-gateway-2, this is the configuration file:

{
“log_level”: “info” ,
“listen_port”: 8080,
“secret”: “352d20ee67be67f6340b4c0605b044b7”,
“template_path”: “/opt/tyk-gateway/templates”,
“tyk_js_path”: “/opt/tyk-gateway/js/tyk.js”,
“middleware_path”: “/opt/tyk-gateway/middleware”,
“use_db_app_configs”: false,
“app_path”: “/opt/tyk-gateway/apps/”,
“storage”: {
“type”: “redis”,
“addrs”:[
“xx.xx.xx.xx:26379”,
“xx.xx.xx.xx:26380”,
“xx.xx.xx.xx:26381”
],
“master_name”:“mymaster”,
“username”: “”,
“password”: “redis_pwd”,
“database”: 0,
“optimisation_max_idle”: 2000,
“optimisation_max_active”: 4000
},
“enable_analytics”: false,
“analytics_config”: {
“type”: “”,
“ignored_ips”:
},
“health_check”: {
“enable_health_checks”: false,
“health_check_value_timeouts”: 60
},
“optimisations_use_async_session_write”: false,
“enable_non_transactional_rate_limiter”: true,
“enable_sentinel_rate_limiter”: false,
“enable_redis_rolling_limiter”: false,
“allow_master_keys”: false,
“policies”: {
“policy_source”: “file”,
“policy_record_name”: “/opt/tyk-gateway/policies/policies.json”
},
“hash_keys”: true,
“close_connections”: false,
“http_server_options”: {
“enable_websockets”: true
},
“allow_insecure_configs”: true,
“coprocess_options”: {
“enable_coprocess”: true,
“coprocess_grpc_server”: “”
},
“enable_bundle_downloader”: true,
“bundle_base_url”: “”,
“global_session_lifetime”: 100,
“force_global_session_lifetime”: false,
“max_idle_connections_per_host”: 500,
“enable_jsvm”: true
}

Is there anything wrong with this kind of architecture? Or in the config file?

How to make it in such a way that when I create an API at Tyk gateway 1, I also can get/ call the API at Tyk Gateway 2?

Regards,

Maan Tarng

No, API definitions and policies are accessed via the local file storage on open source. Redis stores things like your keys, certs, cache response etc.

It’s the architecture and not the config file. You would need a way for your apis to be in sync across your gateways.

There is a good thread about the issue here

@Olu Thanks for your help and explanation.