Redis Stack Server: Cannot Change Data Dir (Docker/Kubernetes)

I am trying to get redis up and running in a Kubernetes environment. I’ve done many tutorials, read the documentation, etc. etc. I need to have the .rdb file and the .aof file(s) saved in a Persistent Volume so that the data can be persisted across Pod (or container) failures/deletions/etc. I have a redis instance starting, and I’m trying to use a custom config file. All the pods get created and run fine and the save variable in the custom config file is updated/correct. However, neither the daemonize nor the dir variables are updated. They remain the default values no matter what I do.

Custom config file:

daemonize yes
cluster-enabled no
dir /redis/storage
port 6397
save 60 5
save 300 1
appendonly yes

I’ve tried using a config map to create the custom config file then using the spec.template.spec.containers.command/spec.template.spec.containers.args to copy the custom config file (named redis-stack.conf) to /etc/, where there’s a redis-stack.conf file that gets overwritten with the data in the custom config file. After the copy command, I have redis-stack-server /etc/redis-stack.conf. When I do kubectl apply -f <filename>.conf, then get a bash shell for one of the created pods and do redis-cli CONFIG GET DIR it is the default dir.

I’ve tried adding redis-cli CONFIG SET DIR <custom dir> at the end of the spec.template.spec.containers.command/spec.template.spec.containers.args string, but that didn’t work either. There are no errors in the logs and nothing but successful events.

I’ve searched the web, but the answers I’ve found that deal with a similar problem don’t solve my issue.

Any help is appreciated.

1 Like

I’ve also looked at the file in the root directory of one of the pods (I have 3 replicas) and noticed that at the very end of the file it looks like it runs:

/opt/redis-stack/bin/redis-server /redis-stack.conf --dir $REDIS_DATA_DIR --protected-mode no 

and then all of the loadmodule commands and anything in $REDIS_ARGS.

However, my understanding is that using the spec.template.spec.containers.command field prevents the file from being used and it doesn’t look like it is being used, but :woman_shrugging:

Hi @jstellman

I don’t know if you’re deploying via our helm-charts, but the current preferred way in kube is to provide a volumeMount in /data. Here’s a recent change the helm chart, that we recently rolled out!

Thanks for the reply. I’m actually not deploying using the helm charts. Maybe I’m missing something, but I’m not sure how this helps me. I have a volumeMount that mounts just fine and is there. The issue is that I need to persist the data (using both the .rdb and the .aof files) and those files need to be in the PersistentVolume I create (and mount).

The problem is that I can’t change the directory (“dir” field ) where the .rdb and .aof files get created/saved at startup. I’m starting redis-stack-server with a custom config file, and some of the values are being set, but not the dir value. The dir value appears to be getting overwritten with the default somehow (and that default value isn’t /data) or that value is just being ignored. My theory is that something is adding a command line argument to my startup command, but I haven’t been able to figure out how to test that yet.

I figured this out. The only way I could get it to use a custom persistence directory was to add the directory as a command line argument when I started redis-stack-server in the spec.template.spec.containers.args (where spec.template.spec.containers.command is [“sh”, “-c”]). So spec.template.spec.container.args is redis-stack-server /path/to/custom-config.conf --dir /path/to/mounted/persistent-volume. This loads everything from the custom config file (except daemonize, which I think actually needs to be no in my case anyway) and also properly sets the custom persistence directory.

It’s amazing what taking a two week break from working on something can do for problem-solving. :wink: