Google-Cloud-Platform

ingress-nginx、GCE 和靜態 IP

  • February 13, 2021

所以,我想要一個指向我的 nginx 入口 LB 的靜態 IP。

gcloud compute addresses create test-ip --global 
gcloud compute addresses describe test-ip  --global

它為我提供了一個我現在可以使用的靜態 IP。

詳細輸出:

address: 34.120.62.131
addressType: EXTERNAL
creationTimestamp: '2021-02-10T10:27:32.806-08:00'
description: ''
id: '6370409738458995579'
ipVersion: IPV4
kind: compute#address
name: dashboard-ip
networkTier: PREMIUM
status: RESERVED

我正在嘗試遵循本指南說明,但“穩定”的 helm repos 已經消失,我嘗試使用的 helm 圖表如下。我不確定這是否是推薦與 helm 一起使用的,但鑑於它歸 K8s 組織所有,這似乎是正確的選擇。

文章中引用的選項不再存在,因此我從圖表中獲取所有值並覆蓋似乎正確的值,儘管我在黑暗中拍攝。

controller:
 service:
   loadBalancerIP: "34.120.62.131"

使用以下方法安裝圖表:


helm install samir ingress-nginx/ingress-nginx -f override.yml

在這一點上,它陷入了狀態。

k logs service/samir-ingress-nginx-controller                                                                                                                                   (gke_esnet-sd-dev_us-central1-c_test-dashboard-ansible/default)
-------------------------------------------------------------------------------
NGINX Ingress controller
 Release:       v0.44.0
 Build:         f802554ccfadf828f7eb6d3f9a9333686706d613
 Repository:    https://github.com/kubernetes/ingress-nginx
 nginx version: nginx/1.19.6

-------------------------------------------------------------------------------

I0211 18:13:45.281578       6 flags.go:208] "Watching for Ingress" class="nginx"
W0211 18:13:45.281650       6 flags.go:213] Ingresses with an empty class will also be processed by this Ingress controller
W0211 18:13:45.282066       6 client_config.go:614] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
I0211 18:13:45.282327       6 main.go:241] "Creating API client" host="https://10.11.240.1:443"
I0211 18:13:45.293561       6 main.go:285] "Running in Kubernetes cluster" major="1" minor="17+" git="v1.17.14-gke.1600" state="clean" commit="7c407f5cc8632f9af5a2657f220963aa7f1c46e7" platform="linux/amd64"
I0211 18:13:45.407646       6 main.go:105] "SSL fake certificate created" file="/etc/ingress-controller/ssl/default-fake-certificate.pem"
I0211 18:13:45.434246       6 ssl.go:532] "loading tls certificate" path="/usr/local/certificates/cert" key="/usr/local/certificates/key"
I0211 18:13:45.473930       6 nginx.go:254] "Starting NGINX Ingress controller"
I0211 18:13:45.495884       6 event.go:282] Event(v1.ObjectReference{Kind:"ConfigMap", Namespace:"default", Name:"samir-ingress-nginx-controller", UID:"7eee0403-5f51-4cda-bd76-84d977ac473e", APIVersion:"v1", ResourceVersion:"446265", FieldPath:""}): type: 'Normal' reason: 'CREATE' ConfigMap default/samir-ingress-nginx-controller
I0211 18:13:46.674807       6 nginx.go:296] "Starting NGINX process"
I0211 18:13:46.675212       6 leaderelection.go:243] attempting to acquire leader lease default/ingress-controller-leader-nginx...
I0211 18:13:46.675645       6 nginx.go:316] "Starting validation webhook" address=":8443" certPath="/usr/local/certificates/cert" keyPath="/usr/local/certificates/key"
I0211 18:13:46.675885       6 controller.go:146] "Configuration changes detected, backend reload required"
I0211 18:13:46.678746       6 status.go:84] "New leader elected" identity="samir-ingress-nginx-controller-57f8695bcc-d4pmq"
I0211 18:13:46.772343       6 controller.go:163] "Backend successfully reloaded"
I0211 18:13:46.772435       6 controller.go:174] "Initial sync, sleeping for 1 second"
I0211 18:13:46.772584       6 event.go:282] Event(v1.ObjectReference{Kind:"Pod", Namespace:"default", Name:"samir-ingress-nginx-controller-57f8695bcc-959pw", UID:"fcb5dbc0-7c43-4330-8641-a00514103afd", APIVersion:"v1", ResourceVersion:"446293", FieldPath:""}): type: 'Normal' reason: 'RELOAD' NGINX reload triggered due to a change in configuration
I0211 18:14:18.716021       6 leaderelection.go:253] successfully acquired lease default/ingress-controller-leader-nginx
I0211 18:14:18.716815       6 status.go:84] "New leader elected" identity="samir-ingress-nginx-controller-57f8695bcc-959pw"

有什麼我想念的嗎?

注意:我確實偶然發現了這個替代圖表。這似乎更接近我在上面連結的stackoverflow文章中引用的內容,儘管即使使用它我也無法讓它工作。創建集群時我可能錯過了一個選項嗎?

我的建議是看一下官方文件,例如,在這裡你可以找到如何為你的 nginx-ingress 控制器分配一個靜態 IP,你也可以參考這個 GCP 教程,它包含一步一步的指南通過 Helm 安裝 Nginx 入口控制器,然後使用外部負載均衡器公開服務,如果您已經保留了 IP,則可以執行以下命令:

helm install -name [nginx-ingress-name] nginx-stable/nginx-ingress --set controller.service.loadBalancerIP=[YOUR_IP]

這與您所遵循的指南中的幾乎相同,如果您沒有事先保留 IP,您只需要讓 GKE 分配 IP 並按照教程進行操作,缺少一個步驟是提升外部 IP靜態如範例中所述

相反,如果您使用 GKE Ingress 控制器,這可以通過在註釋“ kubernetes.io/ingress.global-static-ip-name ”中指定靜態 IP 的名稱輕鬆完成,如此處所述,假設您的 IP 是命名為“test-ip”應該是這樣的:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
 name: my-ingress
 annotations:
   kubernetes.io/ingress.global-static-ip-name: "test-ip"
spec:
...

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