简体   繁体   English

将 redis-sentinel 连接到 Kubernetes 上的 redis-master

[英]Connecting the redis-sentinel to the redis-master on Kubernetes

I have successfully connected the redis-slaves with the redis-master on Kubernetes using the.yaml manifest file that is deployed as pods on kubernetes.我已经使用在 kubernetes 上部署为 pod 的 .yaml 清单文件成功地将 redis-slaves 与 Kubernetes 上的 redis-master 连接起来。

But when I am trying to connect the redis-sentinel to master it gives connection refused "Could not connect to Redis at 127.0.0.1:26379: Connection refused not connected>"但是当我尝试将 redis-sentinel 连接到 master 时,它给出了连接被拒绝“无法在 127.0.0.1:26379 连接到 Redis:连接被拒绝未连接>”

Below is the redis master, slave and sentinel manifest file:下面是 redis 主、从和哨兵清单文件:

Redis-Master.yaml Redis-Master.yaml

kind: Deployment
metadata:
  labels:
    name: redis
    redis-sentinel: "true"
    role: master
  name: redis-master
spec:
  selector:
    matchLabels:
      app: redis
      role: master
      tier: backend
  replicas: 1
  template:
    metadata:
      labels:
        app: redis
        role: master
        tier: backend
    spec:
      containers:
      - name: master
        image: k8s.gcr.io/redis:e2e  # or just image: redis
        env:
          - name: MASTER
            value: "true"
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - containerPort: 6379

Redis-Slave.yaml Redis-Slave.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-slave
  labels:
    app: redis
    role: slave
    tier: backend
spec:
  strategy:
    type: RollingUpdate
  replicas: 3
  selector:
    matchLabels:
      app: redis
      role: slave
      tier: backend
  template:
    metadata:
      labels:
        app: redis
        role: slave
        tier: backend
    spec:
      containers:
        - name: slave
          image: gcr.io/google_samples/gb-redisslave:v3
          ports:
            - name: redis-server
              containerPort: 6379
          env:
            - name: ALLOW_EMPTY_PASSWORD
              value: "yes"
            - name: REDIS_REPLICATION_MODE
              value: slave
            - name: REDIS_MASTER_HOST
              value: redis-master
            - name: REDIS_MASTER_PORT_NUMBER
              value: "6379"

Redis-sentinel Redis-sentinel

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-sentinel
  labels:
    app: redis
    role: sentinel  
    tier: backend
spec:
  strategy:
    type: RollingUpdate
  replicas: 3
  selector:
    matchLabels:
      app: redis
      role: sentinel
      tier: backend
  template:
    metadata:
      labels:
        name: redis-sentinel
        redis-sentinel: "true"
        app: redis
        role: sentinel
        tier: backend
    spec:
      containers:
        - name: sentinel
          image: gcr.io/google_samples/gb-redisslave:v3
          ports:
            - name: redis-sentinel
              containerPort: 26379
          env:
            - name: ALLOW_EMPTY_PASSWORD
              value: "yes"
            - name: REDIS_REPLICATION_MODE
              value: sentinel
            - name: REDIS_MASTER_HOST
              value: redis-master
            - name: REDIS_MASTER_PORT_NUMBER
              value: "6379"   

Can you tell me where am I getting wrong with the redis-sentinel manifest file?你能告诉我 redis-sentinel 清单文件哪里出错了吗?

There are few things you need to consider when deploying Redis-sentinel that can go wrong in your particular use case:在部署 Redis-sentinel 时,您需要考虑的几件事可能会在您的特定用例中出现 go 错误:

  1. Check firewall rules.检查防火墙规则。 Make sure port 26379 of your servers is open.确保您的服务器的端口 26379 已打开。 Sentinels by default run listening for connections to TCP port 26379. Otherwise Sentinels can't talk and can't agree about what to do.默认情况下,Sentinel 会监听与 TCP 端口 26379 的连接。否则,Sentinel 无法交谈,也无法就该做什么达成一致。

  2. Check your Sentinel configuration file - sentinel.conf and Redis configuration file - redis.conf .检查您的 Sentinel 配置文件 - sentinel.conf和 Redis 配置文件 - redis.conf It is mandatory to use a configuration file when running Sentinel, as this file will be used by the system in order to save the current state that will be reloaded in case of restarts.运行 Sentinel 时必须使用配置文件,因为系统将使用该文件来保存当前的 state,以便在重启时重新加载。 Sentinel will simply refuse to start if no configuration file is given or if the configuration file path is not writable.如果没有给出配置文件或配置文件路径不可写,Sentinel 将简单地拒绝启动。

  3. You need at least three Sentinel instances for a robust deployment.您需要至少三个Sentinel 实例才能进行稳健的部署。

You can find more info regarding some of the above info here .您可以在此处找到有关上述某些信息的更多信息。

Please let me know if that helped.请让我知道这是否有帮助。

I am just assuming that you are trying to connect to the pod from outside.我只是假设您正在尝试从外部连接到 pod。 You are connecting to 127.0.0.1 which does not exist inside the Kubernetes environment.您正在连接到 Kubernetes 环境中不存在的 127.0.0.1。 You need to connect to the IP of the Pod which you get by simply running您需要连接到 Pod 的 IP,只需运行即可

kubectl describe pod

or you can create a service and use the name of the service as an env variable in the sentinels.或者您可以创建一个服务并将该服务的名称用作哨兵中的环境变量。

You can't connect it like this.你不能像这样连接它。 You must check services on Kubernetes.您必须检查 Kubernetes 上的服务。 you can see Redis service IP address.可以看到 Redis 服务 IP 地址。 you must connect with the IP address您必须连接到 IP 地址

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM