<p>Lets say I have a Python code on my local machine that listens on localhost and port 8000 as below:</p>

<pre><code>import waitress
app = hug.API(__name__)
app.http.add_middleware(CORSMiddleware(app))
waitress.serve(__hug_wsgi__, host='127.0.0.1', port=8000)
</code></pre>

<p>This code accepts requests on <code>127.0.0.1:8000</code> and send back some response.</p>

<p>Now I want to move this application (with two more related apps) into Docker, and use Kubernetes to orchestrate the communication between them.</p>

<p>But for simplicity, I will take this Python node (app) only.</p>

<p>First I built the docker image using:</p>

<pre><code>docker build -t gcr.io/${PROJECT_ID}/python-app:v1 .
</code></pre>

<p>Then I pushed it into gcloud docker ( I am using google cloud not docker hub):</p>

<pre><code>gcloud docker -- push gcr.io/${PROJECT_ID}/python-app:v1
</code></pre>

<p>Now I created the container cluster:</p>

<pre><code>gcloud container clusters create my-cluster
</code></pre>

<p>Deployed the app into kubernates:</p>

<pre><code>kubectl run python-app --image=gcr.io/${PROJECT_ID}/python-app:v1 --port 8000
</code></pre>

<p>And finally exposed it to internet via:</p>

<pre><code>kubectl expose deployment python-app --type=LoadBalancer --port 80 --target-port 8000
</code></pre>

<p>Now the output of the command <code>kubectl get services</code> is: </p>

<p><a href="https://i.stack.imgur.com/otL5Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/otL5Y.png" alt="kubectl get services"></a></p>

<p>Ok, my question is, I want to send a request from another application (lets say a node js app). </p>

<ol>
<li>How can I do that externally? i.e. from any machine.</li>
<li>How can I do that internally? i.e. from another container pod. </li>
</ol>

<p>How can I let my Python app use those IP addresses and listen on them?</p>

<p>This is the Dockerfile of the Python app:</p>

<pre><code>FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./app.py" ]
</code></pre>

<p>Thanks in advance!</p>

<p><strong>Externally</strong></p>

<p>By running:</p>

<pre><code>kubectl run python-app --image=gcr.io/${PROJECT_ID}/python-app:v1 --port 8000
</code></pre>

<p>You are specifying that your pod listen on port 8000.</p>

<p>By running:</p>

<pre><code>kubectl expose deployment python-app --type=LoadBalancer --port 80 --target-port 8000
</code></pre>

<p>You are specifying that your service listens on port 80, and the service sends traffic to TargetPort 8000 (the port the pod listens on).</p>

<p>So it could be summarised that with your configuration traffic follows the following path:</p>

<pre><code>traffic (port 80) &gt; Load Balancer &gt; Service (Port 80) &gt; TargetPort/Pod (port 8000)
</code></pre>

<p>Using a service of type Load Balancer (rather than the alternative 'Ingress', which creates a service of type Nodeport, and a HTTP(s) Load Balancer rather than a TCP Load Balancer) you are specifying that traffic that targets the pods should arrive at the LoadBalancer on port 80, and then the service directs this traffic to port 8000 on your App. So if you want to direct traffic to your App from an external source, based on the addresses in your screen shot, you would send traffic to 35.197.94.202:80.</p>

<p><strong>Internally</strong></p>

<p>As others have pointed out in the comments, the cluster IP can be used to target pods internally. The port you specify as the service port (in your case 80, although this could be any number you choose for the service) can be used alongside the cluster IP to target the pods on that cluster targeted by the service. For example, you could target: </p>

<p>10.3.254.16:80</p>

<p>However, to target specific pods, you can use the pod IP address and the port the pod listens on. You can discover this by either running a describe command on the pod:</p>

<pre><code>kubectl describe pod
</code></pre>

<p>Or by running:</p>

<pre><code>kubectl get endpoints 
</code></pre>

<p>Which generates the pod IP and port it is listing on. </p>
