kubernetes 在GKE上更改LoadBalancer的IP地址

isr3a4wc  于 2023-05-28  发布在  Kubernetes
关注(0)|答案(2)|浏览(175)

我想在Google Cloud中更改LoadBalancer ingress-nginx-controller的IP地址。我现在已经通过LoadBalancer分配了IP地址。请参见屏幕截图。不幸的是,它没有在GKE中被采用。为什么?那是窃听器吗?GKE lb IP address change

92dk7w1h

92dk7w1h1#

我已经在我的GKE测试集群上验证了这一点。
当您Reserving a static external IP address时,它不会分配给任何VM。取决于你如何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-1creserved IP的集群作为Network Service Tier: PremiumType: Regional,并使用了集群所在的区域-us-central-1. My 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

根据文件:使用以下命令将您的用户初始化为cluster-admin:

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

另外

另外请记住,当您希望强制GKE使用Nginx Ingress功能(如rewrite)时,您应该在ingress资源中添加annotations: kubernetes.io/ingress.class: nginx

avwztpqn

avwztpqn2#

下面的方法效果很好:
先决条件:

  • 已安装入口控制器
  • 已创建Ingress负载均衡器服务
  • 已创建外部负载均衡器
  • 已创建入口资源
  • 静态IP保留

假设需要将静态IP分配为外部负载均衡器IP。
1.本地保存并删除Ingress负载均衡器服务。这也将删除外部负载均衡器。
1.本地保存并删除Ingress Load Balancer。
1.使用以下行重新创建Ingress Load Balancer服务。xxx.xxx.xxx.xxx =您保留的静态IP

spec:
   loadBalancerIP: xxx.xxx.xxx.xxx

1.重新创建入口资源

相关问题