整体架构为configMapstatefulSetserverless 部署 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还没有运行 2dns解析的结果是有延迟的即使master 已经运行 也不能保证 通过configMap里获取的是最新的dns解析的结果 所以直接在 sentinel command里面使用命令 getent host手动获取dns解析结果 是最稳妥的时使用secret配置文件 volumesvolumeMounts 不论是使用configMap或者secret 如果想在容器里使用指定的别名文件对象 都需要使用items进行映射 不然就默认直接使用的配置文件里的keyvolumes: - 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启动服务时就会直接用挂载的配置template: spec: containers: volumeMounts: name:redis-config #这个对应 volumes 里声明的变量 mountPath:/etc/redislivenessProbe 健康检查 restartPolicy重启策略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