0
点赞
收藏
分享

微信扫一扫

【Azure Redis】部署在AKS中的应用连接Redis时候出现Unable to connect to Redis server

君之言之 03-13 22:01 阅读 3

问题描述

在AKS Pod中连接 Azure Redis服务,大概率出现连接不上的问题。大多数的错误为 RedisConnectionException: Unable to connect to Redis server: xxxxxxxxx.redis.cache.chinacloudapi.cn/52.xxx.xxx.xxx:6380

, 但是有时候的错误信息为: RedisConnectionException: Unable to init enough connections amount! only 6 of 24 were initialized. Redis server: xxxxxxxxx.redis.cache.chinacloudapi.cn/52.xxx.xxx.xxx:6380 。

【Azure Redis】部署在AKS中的应用连接Redis时候出现Unable to connect to Redis server _Redis

所以,根据后面的信息判断,Pod并不是完全不能连接Reids服务器,而是只能成功建立部分连接,这是什么问题呢?

 

问题解答

当出现连接Redis服务器Timeout时,第一反应就是要查看客户端和服务端的网络是否连通,是否稳定。

所以进入到Pod所在的节点中,执行 paping 测试,验证了问题在于 连接Redis服务器6380的端口不稳定,经常出现Timeout。

paping -p 6380 xxxxxxxx.redis.cache.chinacloudapi.cn -c 10

结果如下:

【Azure Redis】部署在AKS中的应用连接Redis时候出现Unable to connect to Redis server _Azure_02

证明了是因为AKS所在的网络与Azure Redis之间,存在连通性稳定问题。

进一步调查AKS的网络配置,使用的是默认标准版本的Azure Load Balancer。因为Load Balancer存在出口IP端口限制,默认一个节点的出口端口为1024个,如果节点中所建立的连接过多,占用完SNAT端口数,就会导致新的连接连接不成功 Connection timed out. 

【Azure Redis】部署在AKS中的应用连接Redis时候出现Unable to connect to Redis server _redis_03

(Source: https://docs.azure.cn/zh-cn/aks/load-balancer-standard#configure-the-allocated-outbound-ports)

通过调大默认的SNAT端口限制数后 (1024 ---> 8192), 连接Redis的问题得到解决。

 

## 长Ping结果也变得稳定。

【Azure Redis】部署在AKS中的应用连接Redis时候出现Unable to connect to Redis server _redis_04

 

参考资料

在 Azure Kubernetes 服务 (AKS) 中使用公共负载均衡器  : https://docs.azure.cn/zh-cn/aks/load-balancer-standard#configure-the-allocated-outbound-ports

使用 PSPING 测试连接 : https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-troubleshoot-connectivity#test-connectivity-using-psping

 

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

举报

相关推荐

0 条评论