<p>I am new to devops. I have created an ec2 machine and opened the port 8080, while I am running a simple server I am able to access it publically.</p>

<blockquote>
  <p><a href="http://localhost:8080" rel="nofollow noreferrer">http://localhost:8080</a> (from within the ec2 container) => hello world </p>
  
  <p><a href="http://ec2-15-206-178-112.ap-south-1.compute.amazonaws.com:8080" rel="nofollow noreferrer">http://ec2-15-206-178-112.ap-south-1.compute.amazonaws.com:8080</a> =>  hello world</p>
</blockquote>

<p>Now I have installed a Kubernetes server which is accessible using kubectl from this instance, I am running a simple server on one of the pods and forwarded the port to ec2 8080 port.</p>

<blockquote>
  <p>kubectl port-forward pod/frontend-7496d5f6b8-clfx4 8080:80</p>
</blockquote>

<p>Now from my Ec2 instance I can access it</p>

<blockquote>
  <p><a href="http://localhost:8080" rel="nofollow noreferrer">http://localhost:8080</a> (from within the ec2 container) => hello world from pod</p>
</blockquote>

<p>But I can not access it publically ( port 8080 is open in my security group )</p>

<blockquote>
  <p><a href="http://ec2-15-206-178-112.ap-south-1.compute.amazonaws.com:8080" rel="nofollow noreferrer">http://ec2-15-206-178-112.ap-south-1.compute.amazonaws.com:8080</a> =>  Connection refused</p>
</blockquote>

<p>Can someone point out what am I missing?</p>

nitesh sharma
<p>Kubernetes port forwarding by default binds only to <code>127.0.0.1</code>. That is why you cannot access it using the public interface.</p>

<p>Use the following command to bind to all interfaces:</p>

<pre><code>kubectl port-forward --address 0.0.0.0
</code></pre>

<p>You can check the related GH Issue <a href="https://github.com/kubernetes/kubernetes/issues/40053" rel="nofollow noreferrer">here</a>.</p>
