如何在 Amazon EKS 叢集中標籤 Amazon VPC 子網路,以透過負載平衡器或輸入控制器自動探索子網路?

2 分的閱讀內容
0

我想在 Amazon Virtual Private Cloud (Amazon VPC) 的公有或私有子網路中部署負載平衡器或輸入控制器。為什麼 Kubernetes 無法在我的 Amazon Elastic Kubernetes Service (Amazon EKS) 叢集中探索我的子網路?

簡短描述

Kubernetes 雲端控制器管理員 (cloud-controller-manager) 和 AWS 負載平衡器控制器 (aws-load-balancer-controller) 會查詢叢集的子網路以進行識別。此查詢會使用下列標籤做為篩選條件:

kubernetes.io/cluster/cluster-name

注意: 使用 Amazon EKS 叢集名稱取代 cluster-name

雲端控制器管理員和 AWS 負載平衡器控制器都要求子網路具備下列其中一個標籤:

kubernetes.io/role/elb

-或-

kubernetes.io/role/internal-elb

注意: 如果您未使用前述標籤,則雲端控制器管理員會檢查子網路相關聯的路由表,以識別子網路為公有或私有子網路。與私有子網路不同,公有子網路使用網際網路閘道來取得網際網路直接路由。

如果您沒有將子網路與任一標籤建立關聯,而且使用 AWS 負載平衡器控制器,則會收到錯誤。

例如,如果您要對 Kubernetes 服務進行疑難排解,並執行 kubectl describe service your-service-name 命令,則會收到以下錯誤:

Events:
  Type     Reason                      Age               From                Message
  ----     ------                      ----              ----                -------
  Normal   EnsuringLoadBalancer        9s (x2 over 14s)  service-controller  Ensuring load balancer
  Warning  CreatingLoadBalancerFailed  9s (x2 over 14s)  service-controller  Error creating load balancer (will retry): failed to ensure load balancer for service default/guestbook: could not find any suitable subnets for creating the ELB

如果您要對 Application Load Balancer 輸入控制器進行疑難排解,並執行 kubectl logs your-aws-load-balancer-controller-pod-name 命令,則會收到以下錯誤:

E0121 22:44:02.864753       1 controller.go:217] kubebuilder/controller "msg"="Reconciler error" "error"="failed to build LoadBalancer configuration due to
retrieval of subnets failed to resolve 2 qualified subnets. Subnets must contain the kubernetes.io/cluster/\u003ccluster name\u003e tag with a value of shared or owned and the kubernetes.io/role/elb tag signifying it should be used for ALBs Additionally, there must be at least 2 subnets with unique availability zones as required by ALBs. Either tag subnets to meet this requirement or use the subnets annotation on the ingress resource to explicitly call out what subnets to use for ALB creation. The subnets that did resolve were []"  "controller"="alb-ingress-controller" "request"={"Namespace":"default","Name":"2048-ingress"}

注意: 如果您使用 eksctl 建立 VPC,則該 VPC 中的所有子網路都具有 kubernetes.io/role/elbkubernetes.io/role/internal-elb 標籤。

解決方案

選擇適當的選項來標記您的子網路:

對於負載平衡器資源使用的公有和私有子網路

使用下列鍵值組標記叢集用於負載平衡器資源的所有公有和私有子網路:

Key: kubernetes.io/cluster/cluster-name
Value: shared

注意: 使用 Amazon EKS 叢集名稱取代 cluster-nameshared 值允許一個以上的叢集使用該子網路。

對於內部負載平衡器使用的私有子網路

若要允許 Kubernetes 將私有子網路用於內部負載平衡器,請使用以下鍵值組標記 VPC 中的所有私有子網路:

Key: kubernetes.io/role/internal-elb
Value: 1

對於外部負載平衡器使用的公有子網路

若要允許 Kubernetes 僅將標記的子網路用於外部負載平衡器,請使用以下鍵值組標記 VPC 中的所有公有子網路:

Key: kubernetes.io/role/elb
Value: 1

注意: 在每個可用區域中使用前述標籤,而不是使用公有子網路。


相關資訊

Amazon EKS VPC 和子網路需求和考量事項

GitHub 網站上的子網路自動探索

Amazon EKS 上的應用程式負載平衡

AWS 官方
AWS 官方已更新 1 年前