0

I've installed Bitnami Helm Chart for HA Redis: https://bitnami.com/stack/redis/helm

aleg@Azure:~$ kubectl get pods | grep redis
redis-1580896952-master-0                              1/1     Running   0         67m
redis-1580896952-slave-0                               1/1     Running   0          67m
redis-1580896952-slave-1                               1/1     Running   0          65m

aleg@Azure:~$ kubectl get svc | grep redis
redis-1580896952-headless             ClusterIP      None           <none>          6379/TCP                     67m
redis-1580896952-master               ClusterIP      10.0.244.169   <none>          6379/TCP                     67m
redis-1580896952-slave                ClusterIP      10.0.250.136   <none>          6379/TCP                     67m

How should i connect to it? To service or master pod or something else? Please advice.

Alec
  • 23
  • 1
  • 5

1 Answers1

0

This is nicely explained with Example: Deploying PHP Guestbook application with Redis.

The whole setup process is explained and then the Set up and Expose the Guestbook Frontend is describing how to expose a web frontend serving a HTTP requests. It's configured to connect to redis-master service for write requests and to the redis-slave service for read requests.

Example deployment looks like the following:

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: frontend
  labels:
    app: guestbook
spec:
  selector:
    matchLabels:
      app: guestbook
      tier: frontend
  replicas: 3
  template:
    metadata:
      labels:
        app: guestbook
        tier: frontend
    spec:
      containers:
      - name: php-redis
        image: gcr.io/google-samples/gb-frontend:v4
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        env:
        - name: GET_HOSTS_FROM
          value: dns
          # Using `GET_HOSTS_FROM=dns` requires your cluster to
          # provide a dns service. As of Kubernetes 1.3, DNS is a built-in
          # service launched automatically. However, if the cluster you are using
          # does not have a built-in DNS service, you can instead
          # access an environment variable to find the master
          # service's host. To do so, comment out the 'value: dns' line above, and
          # uncomment the line below:
          # value: env
        ports:
        - containerPort: 80

With that setup you just need to create the frontend service:

apiVersion: v1
kind: Service
metadata:
  name: frontend
  labels:
    app: guestbook
    tier: frontend
spec:
  # comment or delete the following line if you want to use a LoadBalancer
  type: NodePort 
  # if your cluster supports it, uncomment the following to automatically create
  # an external load-balanced IP for the frontend service.
  # type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: guestbook
    tier: frontend

I do recommend reading the docs regarding Redis.

Crou
  • 714
  • 3
  • 9