简体   繁体   English

GKE - 如何将 static ip 附加到内部负载均衡器

[英]GKE - how to attach static ip to internal load balancer

I want to connect service from one GKE cluster to another one.我想将服务从一个 GKE 集群连接到另一个。 I created service as a internal load balancer and I would like to attach a static ip to it.我将服务创建为内部负载平衡器,我想将 static ip 附加到它。 I created my service.yml我创建了我的 service.yml

apiVersion: v1
kind: Service
metadata:
  name: ilb-service
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
    kubernetes.io/ingress.global-static-ip-name: es-test
  labels:
    app: hello
spec:
  type: LoadBalancer
  selector:
    app: hello
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP

However after apply -f when I check the service the load balancer ingress looks like this:但是,在我检查服务时应用 -f 之后,负载均衡器入口看起来像这样:

status:
  loadBalancer:
    ingress:
    - ip: 10.156.0.60

And I cannot connect using the static ip. How to solve it?而且我无法使用static ip连接。如何解决?

EDIT:编辑:

After suggestion I changed the yml file to:
apiVersion: v1
kind: Service
metadata:
  name: ilb-service
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
  labels:
    app: hello
spec:
  type: LoadBalancer
  selector:
    app: hello
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
  loadBalancerIP: "xx.xxx.xxx.xxx" -- here my static ip

Service now looks like it:服务现在看起来像这样:

spec:
  clusterIP: 11.11.1.111
  externalTrafficPolicy: Cluster
  loadBalancerIP: xx.xxx.xxx.xxx
  ports:
  - nodePort: 31894
    port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app: hello
  sessionAffinity: None
  type: LoadBalancer
status:
  loadBalancer: {}

And I still cannot connect我仍然无法连接

You won't use the annotation for the internal IP.您不会使用内部 IP 的注释。 Instead, just specify the IP address you want to use (not by name) in the spec.loadBalancerIP field allows you to specify a numeric IP address to assign to the loadBalancer.相反,只需在spec.loadBalancerIP字段中指定您要使用的 IP 地址(而不是按名称),您就可以指定要分配给 loadBalancer 的数字 IP 地址。 Make sure the IP is not in use anywhere else and is within the same subnet as your cluster.确保该 IP 未在其他任何地方使用,并且与您的集群在同一子网内。

EDIT编辑

To clarify the last statement: If you have the internal IP reserved as a static IP, that IP is no longer available, it is considered "in use" by the static reservation.澄清最后一句话:如果您将内部 IP 保留为静态 IP,则该 IP 不再可用,静态保留将其视为“正在使用”。 To assign the IP to an internal LoadBalancer, the IP must not be reserved nor can it be in use.要将 IP 分配给内部 LoadBalancer,IP 不得保留,也不得使用。

This is not made clear, but it is because of how the GCP controller created internal loadbalancers that it is unable to use an already reserved IP address.这没有说清楚,但由于 GCP 控制器如何创建内部负载均衡器,它无法使用已经保留的 IP 地址。

November 2021 Update 2021 年 11 月更新

It is possible to create a static internal IP and assign it to a LoadBalancer k8s service type.可以创建静态内部 IP 并将其分配给LoadBalancer k8s 服务类型。

  1. Go to the VPC networks -> Select your VPC -> Static Internal IP Addresses转到 VPC 网络 -> 选择您的 VPC -> 静态内部 IP 地址
  2. Click Reserve Static Address , then select a name for your IP and click Reserve .单击“保留静态地址” ,然后为您的 IP 选择一个名称并单击“保留” You can choose IP address manually here as well.您也可以在此处手动选择 IP 地址。
  3. In your Service YAML add the following annotation.在您的服务 YAML 中添加以下注释。 Also make sure type is LoadBalancer and then assign the IP address.还要确保类型是LoadBalancer ,然后分配 IP 地址。
...
annotations: 
  networking.gke.io/load-balancer-type: "Internal"
...
type: LoadBalancer
loadBalancerIP: <your_static_internal_IP>

This will spin up an internal LB and assign your static IP to it.这将启动一个内部 LB 并将您的静态 IP 分配给它。 You can also check in Static Internal IP Addresses screen that new IP is now in use by freshly created load balancer.您还可以在静态内部 IP 地址屏幕中检查新创建的负载均衡器正在使用的新 IP。 You can assign a Cloud DNS record to it, if needed.如果需要,您可以为其分配Cloud DNS记录。 Also, you can choose IP address "shared" during the reservation process so it can be used by up to 50 internal load balancers.此外,您可以在预留过程中选择“共享”IP 地址,以便最多 50 个内部负载平衡器使用它。

Assigning Static IP to Internal LB 为内部LB分配静态IP

Enabling Shared IP 启用共享 IP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM