k8s部署高可用-redis

文章介绍了如何利用GitHub上的spotahome/redis-operator项目在Kubernetes环境中部署和管理高可用性的Redis集群,包括配置自动故障转移的Sentinel。此外,还详细阐述了部署过程,如部署operator控制器、设置Redisfailovers(支持带或不带持久化),以及利用节点亲和性、Pod容忍和拓扑区域限制来优化集群分布。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、项目地址

​GitHub - spotahome/redis-operator: Redis Operator creates/configures/manages high availability redis with sentinel automatic failover atop Kubernetes.​

二、部署过程

一、部署operator控制器

        1.把项目clone下来直接部署方便。

 

到这个目录下的这个文件部署即可,可以修改yaml中的namespace来修改部署的地方。

二、部署redisfailovers.

        1、部署默认的不带持久化

在项目这个目录下找到部署即可。

        2、带持久化

 

三、验证结果

 对应官网中的:

 四、其他特性

下面的是这个项目可以实现的特性,项目中有案例可以直接查看。

NodeAffinity and Tolerations

        1、节点亲和性

        让redis调度到适合的节点上。

        2、Pod的容忍

        让reids容忍一些污点

        3、Pod反亲和性

        让不同的reids调度到不同的node节点上

Topology Spread Contraints

        1、拓扑区域-划分不同的zone来调度不同reids的pod

                1.让redis可以均匀的分布到你希望他调度的节点上

Kubernetes部署Redis高可用可以通过Redis Sentinel或Redis Cluster来实现。这里以Redis Sentinel为例,步骤如下: 1. 创建Redis Sentinel镜像 首先需要创建Redis Sentinel镜像,可以通过以下Dockerfile创建: ``` FROM redis:5.0.7-alpine RUN apk add --no-cache --update curl COPY sentinel.conf /etc/redis/sentinel.conf CMD ["redis-sentinel", "/etc/redis/sentinel.conf"] ``` 其中sentinel.conf是Redis Sentinel的配置文件,可以在其中设置Redis实例的地址、端口等信息。 2. 创建Redis StatefulSet 接着创建Redis StatefulSet,可以参考以下yaml文件: ``` apiVersion: v1 kind: Service metadata: name: redis spec: selector: app: redis ports: - name: redis port: 6379 targetPort: 6379 clusterIP: None --- apiVersion: apps/v1 kind: StatefulSet metadata: name: redis spec: serviceName: redis replicas: 3 selector: matchLabels: app: redis template: metadata: labels: app: redis spec: containers: - name: redis image: redis:5.0.7-alpine command: - redis-server - /etc/redis/redis.conf volumeMounts: - name: redis-config mountPath: /etc/redis - name: sentinel image: my-redis-sentinel:latest volumeMounts: - name: sentinel-config mountPath: /etc/redis volumes: - name: redis-config configMap: name: redis-config - name: sentinel-config configMap: name: sentinel-config volumeClaimTemplates: - metadata: name: data annotations: volume.beta.kubernetes.io/storage-class: "gp2" spec: accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 1Gi ``` 其中,StatefulSet中有两个容器:一个是Redis容器,一个是Redis Sentinel容器Redis容器使用Redis官方镜像,Redis Sentinel容器使用自己创建的Redis Sentinel镜像。同时,还需要创建两个ConfigMap,一个用于Redis配置,一个用于Redis Sentinel配置。 3. 部署Redis Sentinel 最后部署Redis Sentinel,可以参考以下yaml文件: ``` apiVersion: apps/v1 kind: Deployment metadata: name: redis-sentinel spec: replicas: 3 selector: matchLabels: app: redis-sentinel template: metadata: labels: app: redis-sentinel spec: containers: - name: redis-sentinel image: my-redis-sentinel:latest command: - redis-sentinel - /etc/redis/sentinel.conf volumeMounts: - name: sentinel-config mountPath: /etc/redis volumes: - name: sentinel-config configMap: name: sentinel-config ``` 通过部署Redis Sentinel,可以实现Redis集群的高可用。如果Redis主节点出现故障,Redis Sentinel会自动将从节点升级为主节点,从而保证Redis集群的可用性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

A ?Charis

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值