在 EKS 中扩展 Node.js 应用程序 Pod 时使用 Redis 出现超时错误

问题描述 投票:0回答:1

我正在 Amazon EKS 上运行 Node.js 应用程序,该应用程序连接到配置为单节点集群的 Amazon Elastic Cache Redis 实例(节点类型:cache.t3.micro)。安全规则配置正确,应用程序在运行少量 Pod(4 到 10 个之间)时可以成功连接到 Redis。然而,当将应用程序扩展到 20-30 个 Pod 时,我开始遇到 Redis 连接超时错误。

以下是用于在我的 Node.js 应用程序中建立 Redis 连接的代码片段:

const redisClient = require("redis");

const initRedisClient = async () => {
    try {
        info(`connecting to redis client`);
        let connectionClient = redisClient.createClient({
            url : `redis://${redisUrl}:6379`
        });
        connectionClient.on("error",(err) => {
            console.log("error",err);
            throw new Error(err?.message);
        });
        connectionClient.on("connect",function () {
            console.log("redis connected successfully!");
            // storeData("WAIT_TIME","5",false,0);
            // storeData("BUFFER_TIME","2",false,0); 
        })
        await connectionClient.connect();
        client = connectionClient;
        return client;
    } catch (error) {
        console.log(error?.message);
        console.log(error?.message);
        return {
            type : "error",
            message : error?.message
        };
    }
}

环境详情:

  • Node.js 版本:14.x
  • Redis 客户端库/版本:Redis 4.1.0 (https://www.npmjs.com/package/redis
  • Elastic Cache Redis 的节点类型:cache.t3.micro(引擎版本:7.1.0)
  • 集群配置:单节点集群

收到的错误消息与连接超时有关。但是,初始连接或 pod 数量较少没有问题。

我尝试过的:

  • 已验证的安全规则和网络连接似乎都已正确配置。
  • 确保 Redis 实例可运行并可从单个 Pod 进行访问。

任何有关如何排查和解决此问题的见解或建议将不胜感激。

node.js amazon-web-services kubernetes redis
1个回答
0
投票

你能找到解决方案吗?我也面临着同样的问题,但在 EKS 中

© www.soinside.com 2019 - 2024. All rights reserved.