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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)