I'm using DigitalOcean for deployment. I have NestJs app and KeyDb(Redis alternative) containers. I folowed this guide to convert my Docker Compose file to k8s. After successfull deployment on the logs for NestJs I'm getting an error:
[ioredis] Unhandled error event: Error: getaddrinfo EAI_AGAIN keydb
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)
[ioredis] Unhandled error event: Error: connect ETIMEDOUT
at Socket.<anonymous> (/usr/src/app/node_modules/ioredis/built/Redis.js:170:41)
at Object.onceWrapper (node:events:631:28)
at Socket.emit (node:events:517:28)
at Socket._onTimeout (node:net:598:8)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)
[ioredis] Unhandled error event: Error: getaddrinfo EAI_AGAIN keydb
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)
My dockerfile:
# Start with the official Node.js 18 Alpine image
FROM node:18-alpine
# Set the working directory inside the container
WORKDIR /usr/src/app
# Copy package.json and yarn.lock files
COPY package.json yarn.lock ./
# Install dependencies including 'devDependencies' for building the app
RUN yarn install --frozen-lockfile
# Copy the rest of the application code
COPY . .
# Build the application
RUN yarn build
# Expose the port your app will run on
EXPOSE 3000
# Command to start the app
CMD ["node", "dist/main"]
My Docker-Compose File looks like this:
version: '3.8'
services:
keydb:
image: eqalpha/keydb
ports:
- "6379:6379"
networks:
- nestjs-keydb-net
restart: always
nestjs-app:
image: dmytroye/node-kubernetes
ports:
- "80:8080"
depends_on:
- keydb
environment:
- KEYDB_HOST=keydb
- KEYDB_PORT=6379
networks:
- nestjs-keydb-net
restart: always
networks:
nestjs-keydb-net:
driver: bridge
Looks like my NestJs app can't connect to KeyDb, and I just don't know why, and how can I handle this. If you need more code or info - do not hesitate to ping me about it.
Just in case, my Redis constructor:
constructor() {
this.client = new Redis({
host: 'keydb',
port: 6379,
});
}
Solved via configuring an app to call KeyDb via namespaces: