Connect to Redis service from different service using kubernetes

4/28/2018

I have a Kubernetes Cluster on google cloud platform with a number of services deployed. I imported redis-go in my compute service and can create a new client here to store/retrieve data to my redis service. I want to be able to access this stored data from a different service also. I tried using redis-go and creating a new client with the same address to my redis service cluster but I can't retrieve any of the data. So basically I am wondering how I can connect to a single redis-service instance from multiple services. Here is an example of code I am using to Dial my redis-service and store/retrieve value. I can store and retrieve from each individual service but if I store from one service and try retrieve from another it does not work.

      conn, _ := redis.Dial("tcp", "redis:6379")
      defer conn.Close()


      conn.Do("SET", "bbcTrump", "someValue")
    //someValue, _:= conn.Do("GET", "bbcTrump")

In addition here is my redis-deployment.yaml and redis-service.yaml code. Maybe there is a problem here.

Deployment:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert -f docker-compose.yml
    kompose.version: 1.10.0 (HEAD)
  creationTimestamp: null
  labels:
    io.kompose.service: redis
  name: redis
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: redis
    spec:
      containers:
      - image: redis
        name: redis
        ports:
        - containerPort: 6379
        resources: {}

      restartPolicy: Always
status: {}

Service:

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert -f docker-compose.yml
    kompose.version: 1.10.0 (HEAD)
  creationTimestamp: null
  labels:
    io.kompose.service: redis
  name: redis
spec:
  ports:
   - port: 6379
     targetPort: 6379
  selector:
    io.kompose.service: redis
status:
  loadBalancer: {}
-- MATT SHALLOW
go
google-kubernetes-engine
kubernetes
redis

1 Answer

5/13/2018

To fix this I set the image pull policy in my compute-service deployment yaml to always. I also changed its port to :8080 and upgraded my GCP from a trial. One of these or a combination fixed the issue.

-- MATT SHALLOW
Source: StackOverflow