Redis 集群部署
Redis 集群是一个可以在多个 Redis 节点之间进行数据共享的设施(installation)。
[TOC]
Redis 配置文件
创建 redis.conf 配置文件
# 开启 AOF
appendonly yes
# 开启集群
cluster-enabled yes
# 集群配置文件
cluster-config-file nodes.conf
# 集群节点间超时时间
cluster-node-timeout 5000Headless Service
apiVersion: v1
kind: Service
metadata:
name: redis-cluster-svc
namespace: redis-cluster
spec:
selector:
app: redis-cluster
ports:
- port: 6379
# 不设置集群 IP
clusterIP: None开始 Redis Standalone
初始化集群
运行临时 Pod
安装软件
获取 Redis 的 IP

创建集群
本次使用的 Redis 的版本大于 5,因此直接使用 redis-cli 即可。版本小于 5 的,使用 redis-trib。
使用 Headless svc 的方式,但是找不到 Pod IP,所以直接使用上一步操作的 IP。暂时不清楚为什么无头服务会有问题。可能 kube-dns 版本过低,已解决,看下方引用的文字。
The spec.serviceName field in the statefulSet manifest was wrong. It should match the metadata.name field in the headless service definition.
StatefulSet 中的 spec.serviceName 要和 Headless Service 中的 metadata.name 一致

查看集群信息

操作集群

集群会自动按照算法将 key 放到合适的节点上。

测试主从切换
master 1 角色

Node 1 角色

停止 Master 1

查看 Node 1 当前的角色
Slave 角色已变成 Master。

详细 YAML 文件
使用了 NFS-Client,以持久化保存文件。
Last updated
Was this helpful?