Fixed number of pods with a specific purpose (socket connection)

7/19/2017

we are planning to use kubernetes and I am validating, if and how it fits our requirements. One concern is the following: I want to build an application/pod, which is connecting to a certain service on the internet (host and port) and keeps the socket alive as long as we need it (usually forever). The number of sockets the application will connect to may vary. For the inter pod communication we are going to use RabbitMQ.

What is the correct/best practise approach for that purpose? One pod handling all/multiple sockets? Replicated pods handling multiple socket? One Socket per pod? How do i react, if the number of sockets changes?

At the moment we want to use the gitlab-ci and helm for our CI pipeline.

-- psp
gitlab-ci
kubernetes
kubernetes-helm
rabbitmq
sockets

1 Answer

7/19/2017

kubernetes deploys Pods and has two abstractions: Deployments and StatefulSets. The former deploys ephemeral Pods whose hostname and IP changes. The latter retains the state.

If you're deploying kubernetes only for this application, it's an overkill imho. I'd rather use plain Docker or a simpler-than-kubernetes orchestrator such as Docker Swarm Mode or Kontena.

If kubernetes is your only option, you could deploy the app as a StatefulSet. That way its hostname will remain between restarts. Have the app monitor its hostname and connect to the appropriate endpoint. For example, the app-1 Pod connects to endpoint:10001, app-2 Pod connects to endpoint:10002, and so on...

When more Pods are needed to connect to more sockets, either increase the StatefulSet's replicas manually, or write a sidecar application to monitor the no. of sockets and up/down the replicas automatically.

-- Eugene Chow
Source: StackOverflow