所以,我想要一个指向我的 nginx ingress 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 仓库已经消失,我尝试使用的 Helm Chart 是下列的。我不确定这是否是推荐与 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 帖子中引用的内容,尽管即使使用它我也无法使其工作。创建集群时我是否错过了某个选项?
答案1
我的建议是看一下官方文档,例如,这里您可以找到如何为 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 控制器,则可以通过在注释中指定静态 IP 的名称轻松完成此操作“kubernetes.io/ingress.global-static-ip-name“正如所描述的这里,假设你的 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:
...