Running twemproxy as a single replica deployment in kubernetes.
Running redis replicas as statefulsets with with in kubernetes.
Allowing other pods in kubernetes to access twemproxy.
Allowing twemproxy to connect to the redis’s pods.
We can run twemproxy as a single deployment in kubernetes. We can use the following community image jgoodall/twemproxy
twemproxy’s deployment & service spec:
The configuration above will deploy twemproxy’s deployment and service. service in kubernetes allow pods to network with each other, this service will allow other pods to reach twemproxy.
Above is twemproxy’s configuration which need to be mount as configmap volume in twemproxy’s deployment.
Next, we need to create redis’s statefulset. Statefulset with 3 replicas will create the following pods redis-0, redis-1 and redis-2. Pods created by statefulset will be labeled as statefulset.kubernetes.io/pod-name: , we can use this as selector for the service. Unfortunably, we will still need to create 3 services to allow each pod to be addressable by twemproxy,