Redis error using Kube deployment with 3 pods

2/22/2021

So I'm deploying a bot using the GKE, when running locally with docker-compose it works perfectly, but when trying to deploy to the cloud I get the following redis error:

enter image description here

This is my docker compose file:

services:
  salesbot:
    build:
      context: .
    ports:
    - '3000:3000'
    environment:
      - SLACK_TOKEN=xxxxxxxxx
      - SERVER_URL=	https://xxxxxx.ngrok.io
      - REDIS_URL=redis
  redis:
    image: redis:alpine


    command: redis-server /usr/local/etc/redis/redis.conf
    volumes:
      - ./redis.conf:/usr/local/etc/redis/redis.conf
    container_name: 'redis'
  database:
    build:
      context: ./database
    environment:
      - REDIS_URL=redis

I pushed the images for the salesbot and database containers to the Google Container Registry to be able to deploy it in the cloud These are my kube manifests:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: salesbot-deployment
  namespace: salesbot
spec:
  replicas: 1
  selector:
    matchLabels:
      app: salesbot
  template:
    metadata:
      labels:
        app: salesbot
    spec:
      containers:
        - name: salesbot
          image: gcr.io/xxxxx/salesbot-api
          env:
            - name: REDIS_URL
              value: redis
            - name: SERVER_URL
              value: https://xxxxxx.ngrok.io
            - name: SLACK_TOKEN
              value: xxxxxxxx
          ports:
            - containerPort: 3000
          resources:
            requests:
                cpu: 10m
                memory: 30Mi
        
        - name: redis
          image: redis:alpine
          resources: {}
          volumeMounts:
            - mountPath: /usr/local/etc/redis/redis.conf
              name: redis-claim0
          args:
            - redis-server
            - /usr/local/etc/redis/redis.conf

        - name: database
          image: gcr.io/xxxxx/salesbot-db
          env:
            - name: REDIS_URL
              value: redis
          resources:
            requests:
              cpu: 10m
              memory: 30Mi

      volumes:
            - name: redis-claim0
              persistentVolumeClaim:
                claimName: redis-claim0
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  creationTimestamp: null
  labels:
    app: redis
  name: redis-claim0
  namespace: salesbot
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 100Mi
apiVersion: v1
kind: Service
metadata:
  labels:
    app: salesbot
  name: salesbot-svc
  namespace: salesbot
spec:
  ports:
    - port: 80
      targetPort: 3000
  selector:
    app: salesbot
  type: LoadBalancer

Any help will be appreciated!! I don't get why it doesn't work since the deployment its using 3 pods with a container each, and locally in docker I'm also using 3 separate containers. In the cloud the deployment and pods are all running and healthy

-- Ian Spitz
docker
docker-compose
google-kubernetes-engine
kubernetes

1 Answer

2/22/2021

Since you are running all containers in the same pod, you can reach redis at localhost not 'redis'. Change your environment variables accordingly.

On a related note, do you really need all containers running in the same pod? You will not be able to manage them independently (which may be ok depending on your use case)

-- camba1
Source: StackOverflow