Skip to content

Instantly share code, notes, and snippets.

@jithin-scaria
Created May 19, 2022 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jithin-scaria/654dc817a6c0f9c45ab0f092872214fb to your computer and use it in GitHub Desktop.
Save jithin-scaria/654dc817a6c0f9c45ab0f092872214fb to your computer and use it in GitHub Desktop.
Sentinel StatefulSet : Redis High availability with Sentinel on Kubernetes(K8s)
# Sentinel StatefulSet : Redis High availability with Sentinel on Kubernetes(K8s)
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: sentinel
namespace: redis
spec:
serviceName: sentinel
replicas: 3
selector:
matchLabels:
app: sentinel
template:
metadata:
labels:
app: sentinel
spec:
initContainers:
- name: config
image: redis:7.0.0-alpine
command: [ "sh", "-c" ]
args:
- |
REDIS_PASSWORD=admin
nodes=redis-0.redis,redis-1.redis,redis-2.redis
echo "Looping thorugh the redis list to see if Redis Master node is available now"
for i in ${nodes//,/ }
do
MASTER=$(redis-cli --no-auth-warning --raw -h $i -a $REDIS_PASSWORD info replication | awk '{print $1}' | grep master_host: | cut -d ":" -f2)
if [ "$MASTER" == "" ]; then
echo "no master info found in $i"
MASTER=
else
echo "found $MASTER. setting the configurations"
break
fi
done
echo "Creating Sentinel configuration file"
echo "port 5000
sentinel monitor mymaster $MASTER 6379 2
sentinel resolve-hostnames yes
sentinel announce-hostnames yes
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster $REDIS_PASSWORD
" > /etc/redis/sentinel.conf
cat /etc/redis/sentinel.conf
volumeMounts:
- name: redis-config
mountPath: /etc/redis/
containers:
- name: sentinel
image: redis:7.0.0-alpine
command: ["redis-sentinel"]
args: ["/etc/redis/sentinel.conf"]
ports:
- containerPort: 5000
name: sentinel
volumeMounts:
- name: redis-config
mountPath: /etc/redis/
- name: data
mountPath: /data
volumes:
- name: redis-config
emptyDir: {}
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 50Mi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment