2

I am trying to transfer an old legacy system to k8s.

I have a custom server that client apps connect to in order to communicate with one another. Both the server and clients were originally created to run on the same system and communicate using localhost.

I Dockerized both server and client apps. I tested that they work well in the same pod (everything runs well using localhost). Now I would like to separate the server and apps into their own pods. I would like the apps to automatically connect to the server.

Question: How do I connect the client apps to the server without changing the source code of the client apps or server?

2
  • you can try multi container POD if both apps are so tightly coupled.
    – Sunil Bhoi
    Commented Jan 23, 2020 at 5:53
  • @SunilBhoi This would not work for my use case. There will only ever be one server but there can be many apps. This would not scale well. The Sever will have to be vertically scaled while apps can be horizontally scaled.
    – Tim
    Commented Jan 31, 2020 at 16:12

2 Answers 2

1

Are you basically saying that it’s hard coded to “localhost” and you need to somehow change the meaning of “localhost” because you cannot change the source code?

If so, it sounds fairly hard to achieve... but maybe you can override the meaning of localhost in the hosts file of the pod (the right way).

https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/

I feel like this will probably have unintended side effects and may affect kubernetes, but I could be wrong. It’s definitely worth a try.

Note: the overrides can point to services created over the pod deployments if it works :). They can have reliable internal domain names that don’t move around.

1

You can do this by using Kubernetes and Docker's network options. Specifically check out the Kubernetes service documentation for service discovery.

The idea both inside and outside of Kubernetes is that you can add the Docker containers to a defined network, and then discover the services in the network. Depending on how it is configured you may need to run the containers to point to the service name instead of localhost, but again this will vary depending on how you setup your Kubernetes cluster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.