【问题标题】:502 Server Error when creating http load balancer in google/GKE在 google/GKE 中创建 http 负载均衡器时出现 502 服务器错误
【发布时间】:2020-12-23 09:52:42
【问题描述】:

我的应用程序由使用 GKE 部署的 play Web 应用程序组成。应用程序运行良好(使用DeploymentLoadbalancer 服务),然后我决定使用Ingress。我进行了以下更改,导致应用程序无法访问。当我尝试使用ingress IP 连接应用程序时收到502 错误。

应用程序类型为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

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地址(也可以从外部访问)

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 bad gateway 错误

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

【问题讨论】:

    标签: google-cloud-platform google-kubernetes-engine gcp-load-balancer


    【解决方案1】:

    问题是负载平衡器的 IP 不在服务器的允许主机列表中。作为临时修复,我在服务器配置中使用通配符来允许来自所有主机的流量。我仍在研究如何将其限制为负载均衡器的内部 IP

    【讨论】:

    • 您使用的是 VPC 原生集群还是基于路由的集群?
    • 老实说,我不知道。我刚刚使用GKE 创建了一个集群,然后创建了一个load balancer。我怎样才能知道我正在使用什么?
    • 您可以在控制台、Kubernetes Engine > Clusters > YOUR CLUSTER 和详细信息选项卡上查看此内容,您应该会看到 VPC 原生流量路由已启用或已禁用。
    • 已启用 VPC 原生(别名 IP)
    • 那么您应该能够通过仅允许 GFE IP 来实现这一点。 cloud.google.com/load-balancing/docs/https#how-connections-work
    猜你喜欢
    • 2020-07-19
    • 1970-01-01
    • 2018-12-30
    • 2020-10-28
    • 2021-10-14
    • 1970-01-01
    • 2018-04-14
    • 2014-05-03
    • 1970-01-01
    相关资源
    最近更新 更多