我正在使用 Helm 并且不想重新安装它,因此我通过修改 Helm 生成的 configmap 以包含该配置来解决此问题。
CONFIGMAP=<<value of common.names.fullname>>-configuration
kubectl edit cm $CONFIGMAP
您应该会看到如下内容:
master.conf: |-
dir /data
# User-supplied master configuration:
rename-command FLUSHDB ""
rename-command FLUSHALL ""
# End of master configuration
redis.conf: |-
# User-supplied common configuration:
# Enable AOF https://redis.io/topics/persistence#append-only-file
appendonly yes
# Disable RDB persistence, AOF persistence already enabled.
save ""
# End of common configuration
replica.conf: |-
dir /data
slave-read-only yes
# User-supplied replica configuration:
rename-command FLUSHDB ""
rename-command FLUSHALL ""
# End of replica configuration
删除以rename-command 开头的行,使其看起来更像这样:
master.conf: |-
dir /data
# User-supplied master configuration:
# End of master configuration
redis.conf: |-
# User-supplied common configuration:
# Enable AOF https://redis.io/topics/persistence#append-only-file
appendonly yes
# Disable RDB persistence, AOF persistence already enabled.
save ""
# End of common configuration
replica.conf: |-
dir /data
slave-read-only yes
# User-supplied replica configuration:
# End of replica configuration
重启 redis pod
kubectl delete pods $(kubectl get pods | grep redis | awk {'print $1'})
现在执行到主 pod 并刷新所有
kubectl exec redis-master-0 -- redis-cli FLUSHALL
OK
请注意,如果您想再次使用 FLUSHALL 或 FLUSHDB,则在重新安装 Helm 版本时必须再次执行此操作。
更新:虽然这可行,但当您重新安装 helm release 时,pod 将进入 crashloopbackoff,因为它们会在历史记录中看到您运行的命令不存在,因此您必须再次执行此操作让 pod 运行。在这种情况下,可能最好使用@camilo-sampedro 的答案。