nitesh sharma
nitesh sharma

Reputation: 601

AWS ec2 exposed port is not working for Kubernetes forwarded port

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.

http://localhost:8080 (from within the ec2 container) => hello world

http://ec2-15-206-178-112.ap-south-1.compute.amazonaws.com:8080 => hello world

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.

kubectl port-forward pod/frontend-7496d5f6b8-clfx4 8080:80

Now from my Ec2 instance I can access it

http://localhost:8080 (from within the ec2 container) => hello world from pod

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

http://ec2-15-206-178-112.ap-south-1.compute.amazonaws.com:8080 => Connection refused

Can someone point out what am I missing?

Upvotes: 0

Views: 942

Answers (1)

Rafał Leszko
Rafał Leszko

Reputation: 5531

Kubernetes port forwarding by default binds only to 127.0.0.1. That is why you cannot access it using the public interface.

Use the following command to bind to all interfaces:

kubectl port-forward --address 0.0.0.0

You can check the related GH Issue here.

Upvotes: 2

Related Questions