我们在集群中使用KubeDB来管理数据库。
因此,Redis是通过KubeDB Redis对象部署的,并且KubeDB将PVC附加到Redis Pod。
不幸的是,KubeDB还不支持Redis转储的任何还原或备份。
对于备份,我们的解决方案是运行CronJob,该CronJobdump.rdb
从Redis容器复制到作业容器,然后将其上传到S3。
对于恢复转储,我想这样做,反之亦然。有一个临时容器,该容器可以下载S3备份,然后将其复制到Redis容器中dump.rdb
。
该redis.conf
如下所示:
....
# The filename where to dump the DB
dbfilename dump.rdb
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /data
....
复制工作。该dump.rdb
处于正确的位置,正确的权限。我通过使用redis pod在Redis pod中启动第二个redis-server来验证这一点redis.conf
。将dump.rdb
被加载到服务器没有问题。
但是,由于我不想手动启动第二个Redis服务器,因此我重新启动了Redis pod(通过kubectl delete pods)来使该pod拾取复制的dump.rdb
。
每次删除Pod时,都会删除该Pod,dump.rdb
并以dump.rdb
较小的大小(93个字节)创建一个新的Pod 。
我不相信这是PVC问题,因为我创建了一些文件来测试它们是否也被删除。他们不是。只有dump.rdb
。
为什么会这样?我期望Redis仅从中还原数据库dump.rdb
,而不创建新数据库。
编辑:是的,大小dump.rdb
约为47 GB。Redis版本为4.0.11。
如此,几个小时后,我的队友记得Redis执行了一次保存以在关闭时转储。
kubectl delete pod
现在,我不再使用删除pod,而是将代码更改为SHUTDOWN NOSAVE
使用来运行a redis-cli
。
kubectl exec <redis-pod> -- /bin/bash -c 'redis-cli -a $(cat /usr/local/etc/redis/redis.conf | grep "requirepass " | sed -e "s/requirepass //g") SHUTDOWN NOSAVE'
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句