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

时间:2020-09-24 06:49:06

标签: kubernetes google-kubernetes-engine google-cloud-load-balancer

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

1 个答案:

答案 0 :(得分:0)

我已经在我的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.我的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功能(例如rewrite)时,应在GKE资源中添加Nginx Ingress