我无法将redis pod连接到webapp pod

问题描述 投票:0回答:1
Here are logs of webapp pod 


{"date":"2023 年 10 月 9 日星期一 11:50:54 GMT+0530(印度标准时间)","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,“外部”:78028716,“arrayBuffers”:76383815}},“os”:{“loadavg”:[0.65,0.25,0.18],“正常运行时间” :2744194.54},"trace":[{"column":24,"file":"/sails/node_modules/redis/index.js","function":"RedisClient.on_error","line":196,"方法":"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”:[“错误:Redis 连接到 pv-redis:6379 失败 - getaddrinfo ENOTFOUND pv-redis”,“位于 RedisClient.on_error (/sails/node_modules/redis/index.js:196:24) “,”在套接字上。 (/sails/node_modules/redis/index.js:106:14)","在 Socket.emit (events.js:375:28)","在 Socket.emit (domain.js:470:12)", “在emitErrorNT(内部/streams/destroy.js:106:8)”,“在emitErrorCloseNT(内部/streams/destroy.js:74:3)”,“在processTicksAndRejections(内部/process/task_queues.js:82:82: 21)"],"level":"错误","message":"uncaughtException: Redis 连接到 pv-redis:6379 失败 - getaddrinfo ENOTFOUND pv-redis","timestamp":"2023 年 10 月 9 日星期一 11:50: 54"}



Redis pod 应连接 Webapp pod 这是我的 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

这是 webapp yaml 文件

# 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"

docker kubernetes redis web-applications
1个回答
0
投票

"Error: Redis connection to pv-redis:6379 failed - getaddrinfo ENOTFOUND pv-redis"

以上错误日志表明

webapp
pod 正在尝试连接到错误的 redish 服务名称
pv-redis

解决方案:

redis
服务名称更改为
pv-redis

# redis-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: pv-redis
spec:
  selector:
    app: redis
  ports:
    - protocol: TCP
      port: 6379
      targetPort: 6379

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