Routing problem for redis cluster in incoming outside requests
Hello,
I have 3 node my swarm cluster. Redis containers are running on all nodes. I'm set the redis containers to cluster. I am using a docker overlay network.
I have no problems using it in Swarm. My physical and virtual servers outside the swarm are constantly communicating with the containers in the swarm. But I just can not use redis cluster from the outside.
There is no problem when using in Swarm, but the problem starts outside of swarm.
I am sending set/get to redis cluster in swarm over my physical and virtual servers. But it does not always succeed. It's like a network routing problem.
I was using swarm version 3.0.x and upgraded to version 4.0.x. Is this a problem, or is it not a problem, I don't understand.
Does anyone have any information on this? Or is it not possible?
my docker run command..
docker run --name redis --hostname redis -v /data/redis/:/usr/local/etc/redis/ --network test-overlay -p 6379:6379 -d redis:latest redis-server /usr/local/etc/redis/6379.conf
redis-trib create cluster command
docker run --network test-overlay -it --rm sgrio/redis-trib create 172.16.1.111:6379 172.16.1.112:6379 172.16.1.113:6379
Config file
port 6379
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
my "redis-cli" tests from the container;
root@redis:/data# redis-cli -c -h localhost -p 6379
localhost:6379> set test1 test1-results
OK
localhost:6379> set test2 test2-results
OK
172.16.1.113:6379> set test3 test3-results
-> Redirected to slot [13026] located at 172.16.1.113:6379
OK
localhost:6379> get test1
"test1-results"
localhost:6379> get test2
"test2-results"
172.16.1.113:6379> get test3
-> Redirected to slot [13026] located at 172.16.1.113:6379
"test3-results"
My notbook (or outside server..);
root@espala# redis-cli -c -h 10.20.30.40 -p 6379
10.20.30.40:6379> get test1
"test1-results"
10.20.30.40:6379> get test2
"test2-results"
10.20.30.40:6379> get test3
-> Redirected to slot [13026] located at 172.16.1.113:6379
Could not connect to Redis at 172.16.1.113:6379: Operation timed out
Could not connect to Redis at 172.16.1.113:6379: Operation timed out
(150.38s)
localhost:6379> info
# Server
redis_version:4.0.11
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:74253224a862200c
redis_mode:cluster
os:Linux 3.10.0-862.3.3.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:6.3.0
process_id:1
run_id:2feb327dde4a77f3ac40fb0b95b2635f37a1c4ee
tcp_port:6379
uptime_in_seconds:2745
uptime_in_days:0
hz:10
lru_clock:7375627
executable:/data/redis-server
config_file:/usr/local/etc/redis/6379.conf
# Clients
connected_clients:2
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
# Memory
used_memory:1554384
used_memory_human:1.48M
used_memory_rss:10256384
used_memory_rss_human:9.78M
used_memory_peak:1594768
used_memory_peak_human:1.52M
used_memory_peak_perc:97.47%
used_memory_overhead:1511608
used_memory_startup:1444776
used_memory_dataset:42776
used_memory_dataset_perc:39.03%
total_system_memory:10315984896
total_system_memory_human:9.61G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:6.60
mem_allocator:jemalloc-4.0.3
active_defrag_running:0
lazyfree_pending_objects:0
# Persistence
loading:0
rdb_changes_since_last_save:10
rdb_bgsave_in_progress:0
rdb_last_save_time:1534099538
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0
aof_enabled:1
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:0
aof_current_size:339
aof_base_size:0
aof_pending_rewrite:0
aof_buffer_length:0
aof_rewrite_buffer_length:0
aof_pending_bio_fsync:0
aof_delayed_fsync:0
# Stats
total_connections_received:18
total_commands_processed:54
instantaneous_ops_per_sec:0
total_net_input_bytes:61734
total_net_output_bytes:119607
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
expired_stale_perc:0.00
expired_time_cap_reached_count:0
evicted_keys:0
keyspace_hits:15
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0
# Replication
role:master
connected_slaves:0
master_replid:9371e0b469650fdeb951ee0610a6329f39593332
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
# CPU
used_cpu_sys:1.65
used_cpu_user:0.73
used_cpu_sys_children:0.00
used_cpu_user_children:0.00
# Cluster
cluster_enabled:1
# Keyspace
db0:keys=27,expires=0,avg_ttl=0
[root@swarm-node01]# docker --version
Docker version 18.03.1-ce, build 9ee9f40
[root@swarm-node01]# docker network inspect test-overlay
[
{
"Name": "test-overlay",
"Id": "7od0ikhukc1ryw7hmuk9901lf",
"Created": "2018-08-12T20:55:16.917925205+03:00",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.16.1.0/24",
"IPRange": "172.16.1.0/24",
"Gateway": "172.16.1.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
....
"c2cf47e3a880a1c56a24afab2a26077ea89c37d09108333c071398f7b84fa5f8": {
"Name": "redis",
"EndpointID": "71f30ddbf8770560ae1412467c17f95d14cce1f869ee44a2a2edadf40997dabb",
"MacAddress": "02:42:ac:10:01:71",
"IPv4Address": "172.16.1.113/24",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "4097"
},
"Labels": {},
"Peers": [
{
"Name": "ee97d25dee48",
"IP": "10.20.30.40"
},
{
"Name": "43116a9cf8b1",
"IP": "10.20.30.41"
},
{
"Name": "7dbcb8c2d494",
"IP": "10.30.30.42"
}
]
}
]
[root@dev-swarm01 redis]# docker inspect redis
[
{
"Id": "c2cf47e3a880a1c56a24afab2a26077ea89c37d09108333c071398f7b84fa5f8",
"Created": "2018-08-12T18:45:37.865735842Z",
"Path": "docker-entrypoint.sh",
"Args": [
"redis-server",
"/usr/local/etc/redis/6379.conf"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 1156,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-08-12T18:45:38.484480976Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:4e8db158f18dc71307f95260e532df39a9b604b51d4e697468e82845c50cfe28",
"ResolvConfPath": "/var/lib/docker/containers/c2cf47e3a880a1c56a24afab2a26077ea89c37d09108333c071398f7b84fa5f8/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/c2cf47e3a880a1c56a24afab2a26077ea89c37d09108333c071398f7b84fa5f8/hostname",
"HostsPath": "/var/lib/docker/containers/c2cf47e3a880a1c56a24afab2a26077ea89c37d09108333c071398f7b84fa5f8/hosts",
"LogPath": "/var/lib/docker/containers/c2cf47e3a880a1c56a24afab2a26077ea89c37d09108333c071398f7b84fa5f8/c2cf47e3a880a1c56a24afab2a26077ea89c37d09108333c071398f7b84fa5f8-json.log",
"Name": "/redis",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/data/redis/:/usr/local/etc/redis/"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "test-overlay",
"PortBindings": {
"6379/tcp": [
{
"HostIp": "",
"HostPort": "6379"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/0f9b6c136782497a606124d1294dd03e9b802f9c9a12c47b4273b7e7d27fad16-init/diff:/var/lib/docker/overlay2/428bb467708bdee07b3157b2655036f850e2554b4cb45024b512e8c18cbc16e7/diff:/var/lib/docker/overlay2/c6ed7b2d43a3c69cf4d945bc21146d060667d487a89a50786994ede974e6b532/diff:/var/lib/docker/overlay2/a56fa0f740aa5116fe912209250a83073ac3fcf5be55e9c4a46748165f2d8f3f/diff:/var/lib/docker/overlay2/be39f8770118f3594c7e98087014a8595c882badb585852cf186ee7e9bd73ff2/diff:/var/lib/docker/overlay2/3e01a3dc2059156e9e711eb0c3f665dd7127bceba0f959a988390d8811127c95/diff:/var/lib/docker/overlay2/f86a851822a1e12a6fec4a74f07036981deb9821d6818c11db96afc7c1a83a3d/diff",
"MergedDir": "/var/lib/docker/overlay2/0f9b6c136782497a606124d1294dd03e9b802f9c9a12c47b4273b7e7d27fad16/merged",
"UpperDir": "/var/lib/docker/overlay2/0f9b6c136782497a606124d1294dd03e9b802f9c9a12c47b4273b7e7d27fad16/diff",
"WorkDir": "/var/lib/docker/overlay2/0f9b6c136782497a606124d1294dd03e9b802f9c9a12c47b4273b7e7d27fad16/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "bind",
"Source": "/data/redis",
"Destination": "/usr/local/etc/redis",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "volume",
"Name": "bff5857d32cc6d74f17579bcdc15364d8a819b2e352ab717347a2697530acf58",
"Source": "/var/lib/docker/volumes/bff5857d32cc6d74f17579bcdc15364d8a819b2e352ab717347a2697530acf58/_data",
"Destination": "/data",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "redis",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"6379/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.10",
"REDIS_VERSION=4.0.11",
"REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-4.0.11.tar.gz",
"REDIS_DOWNLOAD_SHA=fc53e73ae7586bcdacb4b63875d1ff04f68c5474c1ddeda78f00e5ae2eed1bbb"
],
"Cmd": [
"redis-server",
"/usr/local/etc/redis/6379.conf"
],
"Image": "redis:latest",
"Volumes": {
"/data": {}
},
"WorkingDir": "/data",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "1d1c98cfaacace761609f34a4a5d4edde58853cc28029ba7e0b97be208fe2a56",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"6379/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6379"
}
]
},
"SandboxKey": "/var/run/docker/netns/1d1c98cfaaca",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"test-overlay": {
"IPAMConfig": {
"IPv4Address": "172.16.1.113"
},
"Links": null,
"Aliases": [
"c2cf47e3a880"
],
"NetworkID": "7od0ikhukc1ryw7hmuk9901lf",
"EndpointID": "71f30ddbf8770560ae1412467c17f95d14cce1f869ee44a2a2edadf40997dabb",
"Gateway": "",
"IPAddress": "172.16.1.113",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:10:01:71",
"DriverOpts": null
}
}
}
}
]
It looks like when Redis does that "Redirected to slot xxx" behavior, it doesn't proxy the connection through the Redis server, but rather simply passes the IP address of the appropriate server back to the client, which then initiates the connection directly (which is why you can't hit that Docker-internal IP address from the outside). For this to work, you'll probably have to ensure each instance of Redis has either its own external IP address or at least its own external port, and that they're all clustered using that external reference (since any client of the system needs to be able to access them in the same way they access each other).
Since this issue doesn't seem to denote any errors with the image I'm going to close, you could also try asking the Docker Community Forums, the Docker Community Slack, or Stack Overflow.
how did you solve this problem?
having the same issue any solution?