0

I want to access an application running inside pod from the browser.

Yaml file of pod

apiVersion: v1
kind: Pod
metadata:
  name: app-pod6
  labels:
    name: app-pod
    app: containerization
spec:
  containers:
  - name: appimage1
    image: appimage6:1.0
    ports:
     - containerPort: 3000

When I do

curl localhost:3000/app/home 

its giving me response inside container. Now I want to access it from browser.

I created a service for exposing application using command:

kubectl expose pod app-pod6 --name=app-svc6 --port=3000 --type=NodePort

And when I do describe service, it gives me Nodeport: 31974 And when I do 'ip add', I get kubernetes ip as 192.168.102.128 But cant access application from 192.168.102.128:31974

Azkaban
  • 25
  • 7
  • It looks like the pod is running a `sleep` command, and not a webserver, right? – Jonas Nov 02 '21 at 06:38
  • @Jonas...I have removed it. And added CMD ["sh", "-c", "tail -f /dev/null"] in Dockerfile to keep container running. – Azkaban Nov 02 '21 at 06:57
  • 1
    How would that work? I suggest that you run a webserver listening on port 3000 instead. – Jonas Nov 02 '21 at 06:59
  • @Jonas...when I bash into container, I start the application using startapplication script. And curl localhost:3000/app/home is giving me response. That means app is up inside container on port 3000 – Azkaban Nov 02 '21 at 07:02
  • 1
    Why don't start the application in the command? then you don't need the `sleep` command. – Jonas Nov 02 '21 at 07:12
  • Which IP address are you using? Is that the IP of the node or the Pod? – AndD Nov 02 '21 at 07:24
  • @AndD Its ip address of node – Azkaban Nov 03 '21 at 08:00
  • @Jonas....ive started the app inside pod. And removed sleep. Its not getting exposed still – Azkaban Nov 03 '21 at 08:01
  • Just a thought. Can you make sure the application is not binding on 127.0.0.1? It should be binding to 0.0.0.0 to make itself available to clients outside the container. – JulioHM Nov 03 '21 at 12:26
  • @JulioHM... I have a properties file. In which it is server is already configured to 0.0.0.0 – Azkaban Nov 07 '21 at 09:49
  • Can you show the output of `kubectl get svc -owide -n `? – JulioHM Nov 08 '21 at 13:05

0 Answers0