gpt4 book ai didi

kubernetes - 在 GKE 上更改我的 LoadBalancer 的 IP 地址

转载 作者:行者123 更新时间:2023-12-04 08:52:15 25 4
gpt4 key购买 nike

我想更改 Google Cloud 中 LoadBalancer ingress-nginx-controller 的 IP 地址。我现在已经通过 LoadBalancer 分配了 IP 地址。看截图。不幸的是,它没有在 GKE 中采用。为什么?这是一个错误吗?
GKE lb IP address change

最佳答案

我已经在我的 GKE 上验证了这一点测试集群。
当您Reserving a static external IP address它没有分配给您的任何虚拟机。取决于你如何created cluster/reserved ip (标准或高级)您可能会收到如下错误:

Error syncing load balancer: failed to ensure load balancer: failed to create forwarding rule for load balancer (a574130f333b143a2a62281ef47c8dbb(default/nginx-ingress-controller)): googleapi: Error 400: PREMIUM network tier (the project's default network tier) is not supported: The network tier of specified IP address is STANDARD, that of Forwarding Rule must be the same., badRequest
在这个场景中,我使用了基于 us-central-1c 的集群和 reserved IPNetwork Service Tier: Premium , Type: Regional并使用我的集群所在的区域 - us-central-1.我的 ExternalIP: 34.66.79.1X8 注意 Reserved IP must be in the same reagion as your cluster 选项 1: - 使用 Helm chart
部署 Nginx
helm install nginx-ingress stable/nginx-ingress  --set controller.service.loadBalancerIP=34.66.79.1X8,rbac.create=true
服务输出:
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.8.0.1 <none> 443/TCP 5h49m
nginx-ingress-controller LoadBalancer 10.8.5.158 <pending> 80:31898/TCP,443:30554/TCP 27s
nginx-ingress-default-backend ClusterIP 10.8.13.209 <none> 80/TCP 27s
服务描述输出:
$ kubectl describe svc nginx-ingress-controller
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal EnsuringLoadBalancer 32s service-controller Ensuring load balancer
Normal EnsuredLoadBalancer 5s service-controller Ensured load balancer
最终输出:
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.8.0.1 <none> 443/TCP 5h49m
nginx-ingress-controller LoadBalancer 10.8.5.158 34.66.79.1X8 80:31898/TCP,443:30554/TCP 35s
nginx-ingress-default-backend ClusterIP 10.8.13.209 <none> 80/TCP 35s
选项 2 - 编辑 Nginx部署 Nginx 之前的 YAML
根据文档:
使用以下命令将您的用户初始化为集群管理员:
kubectl create clusterrolebinding cluster-admin-binding \
--clusterrole cluster-admin \
--user $(gcloud config get-value account)
下载 YAML
$ wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.35.0/deploy/static/provider/cloud/deploy.yaml
编辑 LoadBalancer服务并添加 loadBalancerIP: <your-reserved-ip>像下面这样:
# Source: ingress-nginx/templates/controller-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
helm.sh/chart: ingress-nginx-2.13.0
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: 0.35.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
name: ingress-nginx-controller
namespace: ingress-nginx
spec:
type: LoadBalancer
loadBalancerIP: 34.66.79.1x8 #This line
externalTrafficPolicy: Local
ports:
部署它 kubectl apply -f deploy.yaml .服务输出如下:
$ kubectl get svc -A
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.8.0.1 <none> 443/TCP 6h6m
ingress-nginx ingress-nginx-controller LoadBalancer 10.8.5.165 <pending> 80:31226/TCP,443:31161/TCP 17s
ingress-nginx ingress-nginx-controller-admission ClusterIP 10.8.9.216 <none> 443/TCP 18s
6h6m
...
描述输出:
$ kubectl describe svc ingress-nginx-controller -n ingress-nginx
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal EnsuringLoadBalancer 40s service-controller Ensuring load balancer
Normal EnsuredLoadBalancer 2s service-controller Ensured load balancer
保留 IP 的服务:
$ kubectl get svc -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller LoadBalancer 10.8.5.165 34.66.79.1X8 80:31226/TCP,443:31161/TCP 2m22s
ingress-nginx-controller-admission ClusterIP 10.8.9.216 <none> 443/TCP 2m23s
另外
另外请记住,您应该添加 annotations: kubernetes.io/ingress.class: nginx在您的 ingress资源当你想要强制 GKE使用 Nginx Ingress功能,如 rewrite .

关于kubernetes - 在 GKE 上更改我的 LoadBalancer 的 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64040936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com