Kubernetes中具有分片的生产Redis集群

时间:2019-10-28 13:39:37

标签: kubernetes redis

我已经尝试过使用Redis 1e-8'helm'图表来部署一个Redis集群,该集群具有1个主服务器和3个从服务器,可复制写入主服务器的数据。但这是单点故障-我删除了主机,没有重新创建主机的新容器。此外,该图表不支持数据分区(分片)。

编辑:我已经使用头盔stable图表创建了Redis集群,但是没有分片的选项。

是否没有Redis redis-ha图表来部署支持分区(分片)的生产就绪HA集群?您能否指出我可用于设置可管理的Redis集群的资源?首先,我的Redis用于数据缓存,消息处理和流传输。

2 个答案:

答案 0 :(得分:0)

您需要Redis Sentinel。

如果选择helm,这些链接可能会有所帮助:

https://github.com/helm/charts/tree/master/stable/redis(请注意与哨兵相关的配置参数)

https://github.com/helm/charts/tree/master/stable/redis-ha

答案 1 :(得分:0)

关于建立具有分区功能的3个主/ 3个从属redis集群,tutorial很好。它是针对Rancher的,但这是可选的,我刚刚在Azure Kubernetes Service上对其进行了测试,并且效果很好。

首先,应用此Yaml(ConfigMap,具有6个副本的StatefulSet,服务):

apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-cluster
data:
  update-node.sh: |
    #!/bin/sh
    REDIS_NODES="/data/nodes.conf"
    sed -i -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" ${REDIS_NODES}
    exec "$@"
  redis.conf: |+
    cluster-enabled yes
    cluster-require-full-coverage no
    cluster-node-timeout 15000
    cluster-config-file /data/nodes.conf
    cluster-migration-barrier 1
    appendonly yes
    protected-mode no
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis-cluster
spec:
  serviceName: redis-cluster
  replicas: 6
  selector:
    matchLabels:
      app: redis-cluster
  template:
    metadata:
      labels:
        app: redis-cluster
    spec:
      containers:
      - name: redis
        image: redis:5.0.1-alpine
        ports:
        - containerPort: 6379
          name: client
        - containerPort: 16379
          name: gossip
        command: ["/conf/update-node.sh", "redis-server", "/conf/redis.conf"]
        env:
        - name: POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        volumeMounts:
        - name: conf
          mountPath: /conf
          readOnly: false
        - name: data
          mountPath: /data
          readOnly: false
      volumes:
      - name: conf
        configMap:
          name: redis-cluster
          defaultMode: 0755
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
  name: redis-cluster
spec:
  type: ClusterIP
  ports:
  - port: 6379
    targetPort: 6379
    name: client
  - port: 16379
    targetPort: 16379
    name: gossip
  selector:
    app: redis-cluster

下一步是运行此脚本以形成集群(您将必须交互输入一次“是”):

kubectl exec -it redis-cluster-0 -- redis-cli --cluster create --cluster-replicas 1 $(kubectl get pods -l app=redis-cluster -o jsonpath='{range.items[*]}{.status.podIP}:6379 ')
for x in $(seq 0 5); do echo "redis-cluster-$x"; kubectl exec redis-cluster-$x -- redis-cli role; echo; done