无法达到LoadBalancer服务 [英] LoadBalancer service not reachable

查看:148
本文介绍了无法达到LoadBalancer服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的基于HTML,javascript和一点点jquery,angularjs的Web应用程序.它在eclipse Jee和Tomcat上进行了本地测试,并且工作正常.而且它的映像在本地docker上运行良好.

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.

我可以使用localhost:8080/xxxx127.0.0.1:8080/xxxx0.0.0.0:8080在浏览器上访问.但是,当我部署到Google Kubernetes时,如果使用浏览器上的外部IP,则会收到无法访问此站点"的消息.我可以ping我的外部IP,但是curl无法正常工作.这不是防火墙问题,因为dockerhub的示例投票应用程序在我的Kubernetes上运行良好.

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.

我的Dockerfile:

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

我的豆荚豆

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

我的服务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

推荐答案

像这样更改您的Yamls

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

您在Docker映像中公开了端口8080.因此,在服务中,您必须说targetPort: 8080将来自端口80的负载均衡器的流量重定向到容器的端口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

这篇关于无法达到LoadBalancer服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆