Answers: <p>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?</p>
  
  <p>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).</p>
  
  <p><a href="https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/</a></p>
  
  <p>I feel like this will <em>probably</em> have unintended side effects and may affect kubernetes, but I could be wrong.  It’s definitely worth a try.</p>
  
  <p>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.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-01-23T12:48:07.280Z
Answers: 2020-01-23T12:48:07.280Z
Answers: John Humphreys
Answers: <p>You can do this by using Kubernetes and Docker's network options.  Specifically check out the Kubernetes <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">service documentation</a> for service discovery.</p>
  
  <p>The idea both inside and <a href="https://docs.docker.com/engine/reference/commandline/network_connect/" rel="nofollow noreferrer">outside</a> 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.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-01-23T17:55:07.937Z
Answers: 2020-01-23T17:55:07.937Z
Answers: Wesley Rolnick
Body: <p>I am trying to transfer an old legacy system to k8s.</p>
  
  <p>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. </p>
  
  <p>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. </p>
  
  <p>Question: How do I connect the client apps to the server without changing the source code of the client apps or server? </p>
  
Comments: CC BY-SA 4.0
Comments: 2020-01-23T05:53:28.833Z
Comments: you can try multi container POD if both apps are so tightly coupled.
Comments: Sunil Bhoi
Comments: CC BY-SA 4.0
Comments: 2020-01-31T16:12:19.720Z
Comments: @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.
Comments: Tim
Tags: <docker><kubernetes><networking>
Title: localhost Pod to Pod communication k8s
UserDisplayName: Tim
ThreadText: # localhost Pod to Pod communication k8s
  
  (Asked by: username_0 on 2020-01-22)
  
  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?
  
  **Tags:** docker, kubernetes, networking
  
  > **Comments:**
  > **username_1**: you can try multi container POD if both apps are so tightly coupled.  
  > **username_0**: @username_1 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.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-01-23. Score: 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.
  
  
  ---
  
  ### Answer by username_3 on 2020-01-23. Score: 1
  
  You can do this by using Kubernetes and Docker's network options. Specifically check out the Kubernetes [service documentation](https://kubernetes.io/docs/concepts/services-networking/service/) for service discovery.
  
  The idea both inside and [outside](https://docs.docker.com/engine/reference/commandline/network_connect/) 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.
  
  
  ---
  
  