kubectl create -f persistentvolume
kubectl create -f persistentvolumeclaims
kubectl create configmap redis-conf --from-file=redis.conf
kubectl create -f statefulset-services/redis-headless.yaml
kubectl create -f statefulset/redis-statefulset.yaml
kubectl run -i --tty ubuntu --image=ubuntu \
--restart=Never /bin/bash
apt-get update
apt-get install -y vim wget python2.7 python-pip redis-tools dnsutils
Note: redis-trib
doesn't support hostnames (see this issue), so we use dig
to resolve our cluster IPs.
pip install redis-trib
redis-trib.py create \
`dig +short redis-app-0.redis-service.default.svc.cluster.local`:6379 \
`dig +short redis-app-1.redis-service.default.svc.cluster.local`:6379 \
`dig +short redis-app-2.redis-service.default.svc.cluster.local`:6379
redis-trib.py replicate \
--master-addr `dig +short redis-app-0.redis-service.default.svc.cluster.local`:6379 \
--slave-addr `dig +short redis-app-3.redis-service.default.svc.cluster.local`:6379
redis-trib.py replicate \
--master-addr `dig +short redis-app-1.redis-service.default.svc.cluster.local`:6379 \
--slave-addr `dig +short redis-app-4.redis-service.default.svc.cluster.local`:6379
redis-trib.py replicate \
--master-addr `dig +short redis-app-2.redis-service.default.svc.cluster.local`:6379
--slave-addr `dig +short redis-app-5.redis-service.default.svc.cluster.local`:6379
Connect to any redis pod
kubectl exec -it <podName> -- /bin/bash
Access cli
/usr/local/bin/redis-cli -c -p 6379
To check cluster nodes
/usr/local/bin/redis-cli -p 6379 cluster nodes
Originally contributed by Kelsey Hightower (https://github.com/kelseyhightower/kubernetes-redis-cluster)