Connecting to a shared Redis/Valkey cluster through a bastion


Connecting to a shared Redis/Valkey cluster through a bastion

Does connecting to your sharded Valkey Cluster feel like navigating a house of mirrors?

In a recent post I talked about the basics of how to connect to a Redis/Valkey Sharded Cluster.

Let’s say you are setting up a Valkey sharded Elasticache Cluster for a big project that a whole team of developers will be using like I just did, how do you make it so they can access it locally?

How about through a bastion?

The easiest way to connect locally is to have the cli tool installed in the docker image then open up an interactive terminal directly to the running container that was on the same network as the cluster. I used docker compose to spin up my clusters and my application layer. That way they would be on the same network that has access to all the other nodes running in docker.

Obviously you wouldn’t want to package the cli tool in your production image so you would have to make sure that you had one container that was built with that tool baked in but did not have it when it went to production or you could create a custom docker file that builds just the local “Bastion” and open an interactive terminal to that.

What if you wanted to use a Desktop tool to access the cluster running via docker compose? Just exposing the ports that the cluster was running on wouldn’t be enough. When you get hit with one of those “redirects”(see my other post), those by default use the network running in docker, not the host network running on your machine.

What you can do is change the “Announce” settings. I’ll zoom in specifically on Valkey here, specifically on their documented ENV Vars. You will notice a few like VALKEY_CLUSTER_ANNOUNCE_IP that allows you to override what the cluster will send you in that redirect. So if you knew that the IP was always going to be your local you could set that to 127.0.0.1 and the redirect IP would always be your local host.

You could override the port with VALKEY_CLUSTER_ANNOUNCE_PORT to be any port you are forwarding via the bastion to the Elasticache cluster.

You could use a VALKEY_CLUSTER_ANNOUNCE_HOSTNAME to override it as well if you wanted to add some DNS in the middle. Then use VALKEY_CLUSTER_PREFERRED_ENDPOINT_TYPE to tell the cluster to prefer hostname.

It’s a bit of a headache but complexity is the cost of scalability sometimes, at least in infrastructure.

Also I should note that you should be able to do all of these in the .conf as well.

Question:

What Valkey settings are you using overwriting?