Running twemproxy on Kubernetes
Deployments and Services for the redis nodes and twemproxy are found in their respective .yaml
files in deployments/
and services/
.
The port for twemproxy is 22121
, and redis is 6379
quickReset.sh
deletes all deployments and services for quicker development, and quickStart.sh
starts up the redis nodes and twemproxies.
Upon starting up a twemproxy pod, twemproxy/run-twemproxy.sh
is started. This starts the config monitor in the background and is responsible for starting the nutcracker/twemproxy process once a twemproxy.yaml file is created.
twemproxy/config-monitor.sh
monitors any changes in the twemproxy config file that is generated by create-config.py
. If the config file is different than the previous one, the twemproxy process is killed and restarted with the new config file.
create-config.py
uses the kubernetes API to get all redis pods (identified by the label name: redis-node
), and creates a temproxy config file with the IPs of each of those pods.
# Start the redis-node pods
kubectl create -f deployments/redis-node.yaml
kubectl create -f services/redis-node.yaml
# And start the twemproxy pods
kubectl create -f deployments/twemproxy.yaml
kubectl create -f services/twemproxy.yaml
Alternatively, just run quickStart.sh
To access twemproxy through the redis-cli:
kubectl port-forward [twemproxy-pod-name] 6379:22121
In a separate terminal:
redis-cli
# Check that it works:
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
bar
To access a redis instance directly to test sharding:
kubectl port-forward [redis-node-pod-name] 6379:6379
If a redis-node pod is deleted, a new pod is created and twemproxy is restarted (if necessary) to use this new pod's IP.