整体架构为configMap+statefulSet+serverless 部署 sentinel模式 相比较直接直连 master 6379的好处 当master宕机可以立即调度到新的master
开启服务的时候 先开启master ->slave->sentinel
需要注意 使用configmap定义的时候 直接通过sentinel monitor redis-master-0.redis-headless.backend-space.svc.cluster.local 有可能dns 解析不了 1)运行时机,有可能再运行sentinel 读取 configMap时 master pod还没有运行 2)dns解析的结果是有延迟的,即使master 已经运行 也不能保证 通过configMap里获取的是最新的dns解析的结果 所以直接在 sentinel command里面使用命令 getent host手动获取dns解析结果 是最稳妥的
时使用secret配置文件 volumes+volumeMounts 不论是使用configMap或者secret 如果想在容器里使用指定的别名文件对象 都需要使用items进行映射 不然就默认直接使用的配置文件里的key
javascript
volumes:
- name: redis-config
secret:
secretName: redis-secret
defaultMode: 0400 #仅root权限可读
# 或者configMap
# configMap:
# name:
items:
key: 定义配置文件里的key
path: 存储在容器里的别名
redis-server默认启动的配置文件 是在 /etc/redis/redis.conf 所以 直接将secret配置的内容挂载到容器内部的/etc/redis默认启动目录 redis-server启动服务时就会直接用挂载的配置
javascript
template:
spec:
containers:
volumeMounts:
name:redis-config #这个对应 volumes 里声明的变量
mountPath:/etc/redis
livenessProbe 健康检查 + restartPolicy重启策略
javascript
template:
spec:
restartPolicy:Always
containers:
livenessProbe:
exec:
command:
- sh
- -c
- |
# 从 master.conf 中提取 requirepass 并去掉换行
PASSWORD=$(grep -E '^requirepass' /etc/redis/redis.conf | awk '{print $2}' | tr -d '\n\r')
export REDISCLI_AUTH="$PASSWORD"
redis-cli ping