Load-Balancing

Google Container Engine 上使用 Ingress 的 HTTP 負載均衡器

  • August 8, 2017

我試過以下教程:https ://cloud.google.com/container-engine/docs/tutorials/http-balancer

一切似乎都在工作,直到最後

kubectl describe ingress basic-ingress

返回

Name:          basic-ingress
Namespace:      default
Address:        {hidden_external_ip}
Default backend:    nginx:80 ({hidden_internal_ip}:80)
Rules:
 Host  Path    Backends
 ----  ----    --------
 * *   nginx:80 ({hidden_internal_ip}:80)
Annotations:
 backends:     {"k8s-be-00000--0000000000000000":"Unknown"}
 forwarding-rule:  k8s-fw-default-basic-ingress--0000000000000000
 target-proxy:     k8s-tp-default-basic-ingress--0000000000000000
 url-map:      k8s-um-default-basic-ingress--0000000000000000
Events:
 FirstSeen LastSeen    Count   From                SubobjectPath   Type        Reason  Message
 --------- --------    -----   ----                -------------   --    ------    ------  -------
 1m        1m      1   {loadbalancer-controller }          Normal          ADD default/basic-ingress
 23s       23s     1   {loadbalancer-controller }          Normal          CREATE  ip: {hidden_external_ip}

請注意,後端行以“未知”結尾

此外,捲曲外部 IP 會返回:

<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>

知道什麼可能導致這樣的問題嗎?

我想出了兩件事:

  1. 負載均衡器會進行健康檢查/(AFAIK 中沒有記錄),因此您必須確保您的後端在該路徑上返回 200。
  2. 從創建負載均衡器到它“變為活動狀態”(大約 10 分鐘左右)之間存在顯著延遲。當它發生時,行:backends: {"k8s-be-00000--0000000000000000":"Unknown"}將變為:backends: {"k8s-be-00000--0000000000000000":"Healthy"}backends: {"k8s-be-00000--0000000000000000":"Unhealthy"}。這種延遲是問題中連結的教程不起作用的原因(確實應該在那裡記錄……)

引用自:https://serverfault.com/questions/809824