1

I have a very simple web app based on HTML, javascript + little bit jquery, angularjs. It is tested locally on eclipse Jee and on Tomcat and working fine. And its image is working fine on docker locally.

I can access on browser using localhost:8080/xxxx, 127.0.0.1:8080/xxxx, 0.0.0.0:8080. But when I deploy to google Kubernetes, I'm getting "This site can not be reached" if I use the external IP on the browser. I can ping my external IP, but curl is not working. It's not a firewall issue because sample voting app from dockerhub is working fine on my Kubernetes.

my Dockerfile:

FROM tomcat:9.0
ADD GeoWebv3.war /usr/local/tomcat/webapps/GeoWeb.war
expose 8080

my pod yaml

apiVersion: v1
kind: Pod
metadata:   
   name: front-app-pod  
labels:      
   name: front-app-pod     
   app: demo-geo-app
spec:   
   containers:   
      - name: front-app     
      image: myrepo/mywebapp:v2    
   ports:    
     - containerPort: 80

my service yaml

apiVersion: v1
kind: Service
metadata:   
   name: front-service  
labels:     
   name: front-service     
   app: demo-geo-app
spec:  
   type: LoadBalancer   
ports:  
  - port: 80   
  targetPort: 80  
selector:     
   name: front-app-pod      
   app: demo-geo-app
Rico
  • 58,485
  • 12
  • 111
  • 141
  • 1
    Are you trying to use port 80 or 8080? As you're mixing the two in your manifests and description. – johnharris85 Jul 11 '19 at 22:18
  • Trying to use 8080. The 80 on my yamls are remnants from sample voting app yamls. Assumed 80 and 8080 are same. – ENGLISH TEACHER Jul 11 '19 at 22:22
  • Wait, you assume they _are_ the same? Or you have typo's in the above left over from the previous example? Can you correct the examples above if they are wrong? – johnharris85 Jul 11 '19 at 22:29
  • yeah. You were right. I changed every 80 to 8080. I was dumb making this false assumption. If you create an answer, I will accept it. – ENGLISH TEACHER Jul 11 '19 at 22:39

1 Answers1

1

Change your yamls like this

apiVersion: v1
kind: Service
metadata:   
   name: front-service  
labels:     
   name: front-service     
   app: demo-geo-app
spec:  
   type: LoadBalancer   
   ports:  
   - port: 80   
     targetPort: 8080
   selector:     
     name: front-app-pod      
     app: demo-geo-app
apiVersion: v1
kind: Pod
metadata:   
   name: front-app-pod  
labels:      
   name: front-app-pod     
   app: demo-geo-app
spec:   
   containers:   
      - name: front-app     
        image: myrepo/mywebapp:v2    
        ports:    
          - containerPort: 8080

You expose the port 8080 in the docker image. Hence in the service you have to say that the targetPort: 8080 to redirect the traffic coming to load balancer on port 80 to the container's port 8080

maow
  • 2,712
  • 1
  • 11
  • 25
Malathi
  • 2,119
  • 15
  • 40