Kubernetes connection refused although service is exposed as NodePort

9/7/2019

I have an angular server running on kubernetes. If I do

kubectl logs angular-pod-8d5586f44-q2jz3,

I get, at the bottom, the well known

ℹ 「wdm」: Compiled successfully.

Additionally, I have also exposed the service as a NodePort on port 4200, as following lines prove:

angular-client    NodePort    10.102.59.116    <none>        4200:32396/TCP   6s.

However, I get a connection refused error when I try

curl 10.102.59.116:4200
curl: (7) Failed to connect to 10.102.59.116 port 4200: Connection refused.

Has anyone also encountered this problem and know how to fix it ?

By the way, I am using vagrant with virtualbox as vm-machine.

-- Paul Rousseau
angular
kubernetes
vagrant

1 Answer

9/7/2019

If you are using angular-cli, you would have to run ng serve --host 0.0.0.0 in order for angular cli to expose the angular-life-server. However it is not recommended to do this for production purposes, as the angular-life server is not fully reviewed for security concerns, but only meant as a development tool. To deploy you angular app for production, it would be best to do a production build (ng build --prod) and deploy the result inside e.g. a nginx-container.

-- Karsten
Source: StackOverflow