dongzhi2887 2018-05-11 15:17
浏览 86

是否可以在GKE上的多个微服务上共享单个Redis服务器?

I have a redis-service running a redis server. Should I be able to store and retrieve data to that service from multiple clients on different services? I have been unsuccessful in my experiments thus far.

I have a compute-service in its own pod that dials the redis-service and stores a key/value

rClient := redis.NewClient(&redis.Options{
    Addr:     "redis-service:6379",
    Password: "", // no password set
    DB:       0,  // use default DB
})

rClient.Set("trump", "value", 0).Err()

I then have a web-service in its own pod that tries to read this value. Error returns Nil and the value is blank.

rClient := redis.NewClient(&redis.Options{
    Addr:     "redis-service:6379",
    Password: "", // no password set
    DB:       0,  // use default DB
})

val, err := rClient.Get("trump").Result()

fmt.Fprintf(w, "Print Error: %v 
", err) //prints nil

fmt.Fprintf(w, "Print Value: %s 
", val) // blank

If I set the value in the web-service then I can read the value fine. I just cant seem to set the value in a different service. As far as I know Redis stores data on the server side which would be redis-service.

Here is my redis-service deployment/service yaml files. Maybe it is the configuration?

   apiVersion: v1
kind: Service
metadata:
  name: redis-service
  labels:
    app: redis-service
    role: master
    tier: backend
spec:
  ports:
  - port: 6379
    targetPort: 6379
  selector:
    app: redis-service


apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: redis-service
spec:
  selector:
    matchLabels:
      app: redis-service
      role: master
      tier: backend
  replicas: 1
  template:
    metadata:
      labels:
        app: redis-service
        role: master
        tier: backend
    spec:
      containers:
      - name: redis-service
        image: k8s.gcr.io/redis:e2e  # or just image: redis
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - containerPort: 6379 
  • 写回答

1条回答

  • dov11020 2018-05-13 10:36
    关注

    This issue has been resolved. I set the Image pull policy to always in my compute-service deployment yaml. I also changed its port from :9090 to 8080 thinking the port might have been used elsewhere. Finally I upgraded my GCP account from a trial. I am not sure exactly which one of these fixed the issue but I am relieved it is resolved now.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题