Here are logs of webapp pod
{"date":"Mon Oct 09 2023 11:50:54 GMT+0530 (India Standard
Time)","process":{"pid":1,"uid":0,"gid":0,"cwd":"/sails","execPath":"/root/.nvm/versions/node/v14.17.1/bin/node","version":"v14.17.1","argv":["/root/.nvm/versions/node/v14.17.1/bin/node","/sails/app.js","–prod","–port","8080"],"memoryUsage":{"rss":255209472,"heapTotal":187183104,"heapUsed":154731976,"external":78028716,"arrayBuffers":76383815}},"os":{"loadavg":[0.65,0.25,0.18],"uptime":2744194.54},"trace":[{"column":24,"file":"/sails/node_modules/redis/index.js","function":"RedisClient.on_error","line":196,"method":"on_error","native":false},{"column":14,"file":"/sails/node_modules/redis/index.js","function":null,"line":106,"method":null,"native":false},{"column":28,"file":"events.js","function":"Socket.emit","line":375,"method":"emit","native":false},{"column":12,"file":"domain.js","function":"Socket.emit","line":470,"method":"emit","native":false},{"column":8,"file":"internal/streams/destroy.js","function":"emitErrorNT","line":106,"method":null,"native":false},{"column":3,"file":"internal/streams/destroy.js","function":"emitErrorCloseNT","line":74,"method":null,"native":false},{"column":21,"file":"internal/process/task_queues.js","function":"processTicksAndRejections","line":82,"method":null,"native":false}],"stack":["Error:
Redis connection to pv-redis:6379 failed – getaddrinfo ENOTFOUND
pv-redis"," at RedisClient.on_error
(/sails/node_modules/redis/index.js:196:24)"," at
Socket. (/sails/node_modules/redis/index.js:106:14)","
at Socket.emit (events.js:375:28)"," at Socket.emit
(domain.js:470:12)"," at emitErrorNT
(internal/streams/destroy.js:106:8)"," at emitErrorCloseNT
(internal/streams/destroy.js:74:3)"," at processTicksAndRejections
(internal/process/task_queues.js:82:21)"],"level":"error","message":"uncaughtException:
Redis connection to pv-redis:6379 failed – getaddrinfo ENOTFOUND
pv-redis","timestamp":"Mon Oct 09 2023 11:50:54"}
Redis pod should connect Webapp pod
here is my redis pod yaml
# redis-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis
ports:
- containerPort: 6379
---
# redis-service.yaml
apiVersion: v1
kind: Service
metadata:
name: redis
spec:
selector:
app: redis
ports:
- protocol: TCP
port: 6379
targetPort: 6379
and this is webapp yaml file
# webapp-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp
spec:
replicas: 1
selector:
matchLabels:
app: webapp
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: webapp
image: 849324552297.dkr.ecr.ap-south-1.amazonaws.com/pv-webapp
env:
- name: REDIS_HOST
value: "redis"
- name: REDIS_PORT
value: "6379"
2
Answers
"Error: Redis connection to pv-redis:6379 failed - getaddrinfo ENOTFOUND pv-redis"
Above error log indicates that the
webapp
pod is trying to connect to wrong redish service namepv-redis
.Solution:
Change the
redis
service name topv-redis
The error you’re encountering, "Redis connection to
pv-redis:6379
failed – getaddrinfo ENOTFOUNDpv-redis
," indicates that your webapp pod is unable to resolve the hostname "pv-redis" to an IP address. This usually happens when the hostname is not resolvable within the Kubernetes cluster. To resolve this issue, you can make the following adjustments:Use Kubernetes Service DNS Name:
You should use the Kubernetes service DNS name for the Redis service when specifying the
REDIS_HOST
environment variable in your webapp deployment. The service name is usually in the formatservicename.namespace.svc.cluster.local
.Update your
webapp-deployment.yaml
as follows:This change ensures that the webapp pod can resolve the hostname "redis" to the IP address of the Redis service within the same Kubernetes cluster.
Verify Kubernetes Namespace:
Make sure that both your Redis deployment and webapp deployment are in the same Kubernetes namespace. If they are in different namespaces, you’ll need to specify the full service name with the correct namespace in the REDIS_HOST environment variable.
Check for Other Network Issues:
Ensure there are no network policies or other configurations that might be preventing network communication between pods in your cluster.
After making these changes, your webapp pod should be able to connect to the Redis pod using the correct DNS name, and the "getaddrinfo ENOTFOUND" error should be resolved.