access docker container in kubernetes
<p>I have a docker container with an application exposing port 8080.
I can run it and access it on my local computer:</p>

<pre><code>$ docker run -p 33333:8080 foo
* Running on http://127.0.0.1:8080/ (Press CTRL+C to quit) 
</code></pre>

<p>I can test it with:</p>

<pre><code>$ nc -v locahost 33333
connection succeeded!
</code></pre>

<p>However when I deploy it in Kubernetes it doesn't work.
Here is the manifest file:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: foo-pod
  namespace: foo
  labels:
    name: foo-pod
spec:
  containers:
  - name: foo
    image: bar/foo:latest
    ports:
    - containerPort: 8080
</code></pre>

<p>and</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: foo-service
  namespace: foo
spec:
  type: NodePort
  ports:
    - port: 8080
    - NodePort: 33333
  selector:
    name: foo-pod
</code></pre>

<p>Deployed with:</p>

<pre><code>$ kubectl apply -f foo.yaml 
$ nc -v &lt;publicIP&gt; 33333
Connection refused 
</code></pre>

<p>I don't understand why I cannot access it...</p>

<p>The problem  was that the application was listening on IP <code>127.0.0.1</code>.
It needs to listen on <code>0.0.0.0</code> to work in kubernetes. A change in the application code did the trick.</p>

python docker kubernetes