在google/GKE中创建http负载均衡器时出现502服务器错误 [英] 502 Server Error when creating http load balancer in google/GKE

查看:78
本文介绍了在google/GKE中创建http负载均衡器时出现502服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序由使用GKE部署的 play Web应用程序组成.该应用程序运行良好(使用 Deployment Loadbalancer 服务),然后我决定使用 Ingress .我进行了以下更改,使应用程序无法访问.尝试使用 ingress IP与应用程序连接时,出现 502 错误.

My application consists of play web application deployed using GKE. The application was running fine (using Deployment and Loadbalancer service) and then I decided to use Ingress. I made the following changes which has made the application unreachable. I get 502 error when I try to connect with the application using ingress IP.

该应用程序为 Deployment .

apiVersion: apps/v1
kind: Deployment
metadata:
  name: webapp
spec:
  replicas: 2
  selector:
    matchLabels:
      app: webapp

它具有与 service 相关的

apiVersion: v1
kind: Service
metadata:
  name: webapp-service
spec:
  selector:
    app: webapp
  ports:
    - protocol: TCP
      port: 9000 #this service is reachable at this port
      targetPort: 9000 #this service will forward the request to correspoding nodes of the service at this port
  #type: LoadBalancer
  type: NodePort

然后我将以下文件应用于创建 ingress

Then I applied the following file to create ingress

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: webapp-https-loadbalancer-ingress
  annotations:
    kubernetes.io/ingress.class: "gce"
spec:
  rules:
    - http:
        paths:
          - path: /*
            backend:
              serviceName: webapp-service
              servicePort: 9000

运行时我看到有一个IP地址(也可以从外部访问)

I can see that there is an IP address (which is also reachable from outside) when I run

kubectl describe ingress webapp-https-loadbalancer-ingress
Name:             webapp-https-loadbalancer-ingress
Namespace:        default
Address:          3x.yyy.zzz.pq
Default backend:  default-http-backend:80 (10.88.0.5:8080)
Rules:
  Host        Path  Backends
  ----        ----  --------
  *
...      Type    Reason  Age    From                     Message
      ----    ------  ----   ----                     -------
      Normal  ADD     10m    loadbalancer-controller  default/webapp-https-loadbalancer-ingress
      Normal  CREATE  9m10s  loadbalancer-controller  ip: 3x.yyy.zzz.pq

但是我无法使用 https://3x.yyy.zzz.pq 访问该应用程序.我尚未将域名与IP相关联.我尝试使用 curl 进行连接,并收到错误- 502错误的网关错误

But I am not able to reach the application using https://3x.yyy.zzz.pq. I haven't yet associated the domain with the IP. I tried to connect using curl and got error- 502 bad gateway error

curl -v 3x.xxx.xxx.xxx
* Expire in 0 ms for 6 (transfer 0x55d4c5258f90)
*   Trying 3x.xxx.xxx.xxx...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x55d4c5258f90)
* Connected to 3x.xxx.xxx.xxx (3x.xxx.xxx.xxx) port 80 (#0)
> GET / HTTP/1.1
> Host: 3x.xxx.xxx.xxx
> User-Agent: curl/7.64.0
> Accept: */*
>
< HTTP/1.1 502 Bad Gateway
< Content-Type: text/html; charset=UTF-8
< Referrer-Policy: no-referrer
< Content-Length: 332
< Date: Tue, 22 Dec 2020 22:27:23 GMT
<

<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>502 Server Error</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Server Error</h1>
<h2>The server encountered a temporary error and could not complete your request.<p>Please try again in 30 seconds.</h2>
<h2></h2>
</body></html>
* Connection #0 to host 3x.xxx.xxx.xxx left intact

推荐答案

问题是负载均衡器的IP不在服务器的允许主机列表中.作为临时解决方案,我在服务器配置中使用了通配符,以允许来自所有主机的流量.我仍在弄清楚如何将其限制为负载均衡器的内部IP

The issue was that the load balancer's IP was not in the allowed-hosts list in the server. As temporary fix, I used wild card in server configuration to allow traffic from all hosts. I am still figuring out how to restrict it to load balancer's internal IPs

这篇关于在google/GKE中创建http负载均衡器时出现502服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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