I have successfully connected the redis-slaves with the redis-master on Kubernetes using the .yaml manifest file that is deployed as pods on kubernetes.
But when I am trying to connect the redis-sentinel to master it gives connection refused "Could not connect to Redis at 127.0.0.1:26379: Connection refused not connected>"
Below is the redis master, slave and sentinel manifest file:
Redis-Master.yaml
kind: Deployment
metadata:
labels:
name: redis
redis-sentinel: "true"
role: master
name: redis-master
spec:
selector:
matchLabels:
app: redis
role: master
tier: backend
replicas: 1
template:
metadata:
labels:
app: redis
role: master
tier: backend
spec:
containers:
- name: master
image: k8s.gcr.io/redis:e2e # or just image: redis
env:
- name: MASTER
value: "true"
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 6379
Redis-Slave.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-slave
labels:
app: redis
role: slave
tier: backend
spec:
strategy:
type: RollingUpdate
replicas: 3
selector:
matchLabels:
app: redis
role: slave
tier: backend
template:
metadata:
labels:
app: redis
role: slave
tier: backend
spec:
containers:
- name: slave
image: gcr.io/google_samples/gb-redisslave:v3
ports:
- name: redis-server
containerPort: 6379
env:
- name: ALLOW_EMPTY_PASSWORD
value: "yes"
- name: REDIS_REPLICATION_MODE
value: slave
- name: REDIS_MASTER_HOST
value: redis-master
- name: REDIS_MASTER_PORT_NUMBER
value: "6379"
Redis-sentinel
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-sentinel
labels:
app: redis
role: sentinel
tier: backend
spec:
strategy:
type: RollingUpdate
replicas: 3
selector:
matchLabels:
app: redis
role: sentinel
tier: backend
template:
metadata:
labels:
name: redis-sentinel
redis-sentinel: "true"
app: redis
role: sentinel
tier: backend
spec:
containers:
- name: sentinel
image: gcr.io/google_samples/gb-redisslave:v3
ports:
- name: redis-sentinel
containerPort: 26379
env:
- name: ALLOW_EMPTY_PASSWORD
value: "yes"
- name: REDIS_REPLICATION_MODE
value: sentinel
- name: REDIS_MASTER_HOST
value: redis-master
- name: REDIS_MASTER_PORT_NUMBER
value: "6379"
Can you tell me where am I getting wrong with the redis-sentinel manifest file?
I am just assuming that you are trying to connect to the pod from outside. You are connecting to 127.0.0.1 which does not exist inside the Kubernetes environment. You need to connect to the IP of the Pod which you get by simply running
kubectl describe pod
or you can create a service and use the name of the service as an env variable in the sentinels.
There are few things you need to consider when deploying Redis-sentinel that can go wrong in your particular use case:
Check firewall rules. Make sure port 26379 of your servers is open. Sentinels by default run listening for connections to TCP port 26379. Otherwise Sentinels can't talk and can't agree about what to do.
Check your Sentinel configuration file - sentinel.conf
and Redis configuration file - redis.conf
. It is mandatory to use a configuration file when running Sentinel, as this file will be used by the system in order to save the current state that will be reloaded in case of restarts. Sentinel will simply refuse to start if no configuration file is given or if the configuration file path is not writable.
You need at least three Sentinel instances for a robust deployment.
You can find more info regarding some of the above info here.
Please let me know if that helped.