Creating a connection string in the cloud for Redis

Viewed 627

I have a Redis pod, and I expect connection requests to this pod from different clusters and applications not running in the cloud. Since Redis does not work with the http protocol, accessing as the route I have done below does not work with this connection string "route-redis.local:6379".

  • route.yml
apiVersion: v1
kind: Route
metadata:
  name: redis
spec:
  host: route-redis.local
  to:
    kind: Service
    name: redis
  • service.yml

     apiVersion: v1
     kind: Service
     metadata:
       name: redis
     spec:
       ports:
       - port: 6379
         targetPort: 6379
       selector:
         name: redis
    

You may have encountered this situation. In short, is there any way to access to the redis pod via route? If not, how do you solve this problem?

2 Answers

You already discovered that Redis does not work via the HTTP protocol, which is correct as far as I know. Routes work by inspecting the HTTP Host header for each request, which will not work for Redis. This means that you will not be able to use Routes for non-HTTP workload.

Typically, such non-HTTP services are exposed via a Service and NodePorts. This means that each Worker Node that is part of your cluster will open this port and will forward the traffic to your application.

You can find more information in the Kubernetes documentation:

NodePort: Exposes the Service on each Node's IP at a static port (the NodePort). A ClusterIP Service, to which the NodePort Service routes, is automatically created. You'll be able to contact the NodePort Service, from outside the cluster, by requesting :.

You can define a NodePort like so (this example is for MySQL, which is also non-HTTP workload):

apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    name: mysql
spec:
  type: NodePort
  ports:
    - port: 3306
      nodePort: 30036
      name: http
  selector:
    name: mysql

Of course, your administrator may limit the access to these ports, so it may or may not be possible to use these types of services on your OpenShift cluster.

Related