<p>I have several pods, for example a python web app and a redis(shared by other apps), so I need to place redis in a separate pod. But they are all use the same subnet from docker(172.17.0.0/16) or even the same ip address. how can app pods talk with redis pod?</p>

<p>Maybe what I want ask is what's the best way to setup multi-host conainer networking.</p>

<hr>

<p>7 weeks later, I get more familiar with kubernetes. I know kubernetes has network assuming that pods can access each other. so if you app service pod need to access a shared service(redis) pod, you need expose the the shared service as a kubernetes service, then you can get the shared service endpoint from app pods' environment variables or hostname.</p>

<p>When you create a service, the service will proxy the connection to the different pods.</p>

<p>A service therefore maintains the list of IPs of the pods' containers.</p>

<p>You can then look those up in the API</p>

<p>they will be at </p>

<pre><code>http(s)://${KUBERNETES_SERVICE_HOST}/api/v1/namespaces/${NAMESPACE}/endpoints/${SERVICE_NAME}
</code></pre>

<p>NAMESPACE is the name of the namespace. By default it is default, so if you didn't set a namespace in the pod replace with 'default' 
SERVICE_NAME is your service name
KUBERNETES_SERVICE_HOST is an environment variable available in your container.</p>

<p>You will get a JSON object with containers and "ip" tags.
You can then pipe the answer to a </p>

<pre><code>grep '\"ip\"' | awk '{print $2}' | awk -F\" '{print $2}' 
</code></pre>

<p>do isolate the IPs</p>

<p>You might also need credentials to reach the https (test it with curl) 
in Google Cloud, credentials can be found by looking up </p>

<pre><code>gcloud cluster-info &lt;your-cluster-name&gt;
</code></pre>

<p>Note: even if you don't use the service to talk to your pods, it serves the purpose of gathering the IPs for your pods. However note that these may change if the pod get rescheduled somewhere else when a node fails,<br>
the Service takes care of maintaining the up-to-date list, but your app needs to pull at intervals or set a watch on the endpoints to keep it's list up to date.</p>
