Kubernetes Redis HA and exposing redis to things outside of the container

5k views Asked by At

I am trying to learn docker and kubernetes and one of the things I am trying to do is setup Redis with Sentinel and expose redis to things outside the container.

Getting redis and sentinel setup was pretty easy following https://github.com/kubernetes/kubernetes/tree/master/examples/storage/redis

But now my next desire is to be able to access redis outside the container and I can't figure out who to expose sentinel and the master pod.

1

There are 1 answers

5
Norbert On

The redis sentinel service file from your link (https://github.com/kubernetes/kubernetes/blob/master/examples/storage/redis/redis-sentinel-service.yaml) will expose the pods within the cluster. For external access (from outside your cluster) you can use a NodePort:

apiVersion: v1
kind: Service
metadata:
  labels:
    name: sentinel
    role: service
  name: redis-sentinel
spec:
  type: NodePort
  ports:
    - port: 26379
      targetPort: 26379
      nodePort: 30369
  selector:
    redis-sentinel: "true"

This would expose the port 30369 on all your hosts from the outside world to the redis sentinel service.

Several remarks on this: * Firewall: Security in redis is limited, so prevent unwanted access before opening the port * The allowed to be assigned nodePort range is from 30000 to 32767, so be creative with this limitation.