Cannot access exposed Dockerized React app on Kubernetes
The short version is that the Service is listening on the same TCP/IP port on every Node in your cluster (34604
) as is shown in the output of describe service
:
NodePort: <unset> 34604
If you wish to access the application through a "nice" URL, you'll want a load balancer that can translate the hostname into the in-cluster IP and port combination. That's what an Ingress controller is designed to do, but it isn't the only way -- changing the Service to be type: LoadBalancer
will do that for you, if you're running in a cloud environment where Kubernetes knows how to programmatically create load balancers for you.
I believe you found the answer by now :), I landed here as I was facing this issue. Solved for self, hope this helps everyone.
Here's what can help:
- Deploy your app (say: react-app).
- Run below command:
kubectl expose deployment <workload> --namespace=app-dev --name=react-app --type=NodePort --port=3000 output: service/notesui-app exposed
Publish the service port as 3000, Target Port 3000, Node Port (auto selected 32250)
kubectl get svc react-app --namespace=notesui-devNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEreact-app NodePort 10.23.22.55 <none> 3000:32250/TCP 48m
Yaml: (sample)
apiVersion: v1kind: Service name: react-app namespace: app-devspec: selector: <workload> ports: - nodePort: 32250 port: 3000 protocol: TCP targetPort: 3000 type: NodePortstatus: {}
Access the app on browser:
http://<Host>:32250/index
is your node ip where pod is running.If you have app running in multiple nodes (scaled). It is a NodePort setting on every node.App can be accessed:
http://<Host1>:32250/indexhttp://<Host2>:32250/index