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

GKE - how to attach static ip to internal load balancer

我想将服务从一个 GKE 集群连接到另一个。我将服务创建为内部负载均衡器,我想为其附加一个静态 ip。我创建了 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

然而,当我检查服务时应用 -f 后,负载均衡器入口看起来像这样:

status:
  loadBalancer:
    ingress:
    - ip: 10.156.0.60

而且我无法使用静态 ip 连接。如何解决?

编辑:

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

服务现在看起来像:

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: {}

我还是连接不上

2021 年 11 月更新

可以创建静态内部 IP 并将其分配给 LoadBalancer k8s 服务类型。

  1. 转到 VPC 网络 -> Select 你的 VPC -> 静态内部 IP 地址
  2. 点击保留静态地址,然后select为你的IP命名并点击保留。您也可以在这里手动选择 IP 地址。
  3. 在您的服务 YAML 中添加以下注释。还要确保类型是 LoadBalancer,然后分配 IP 地址。
...
annotations: 
  networking.gke.io/load-balancer-type: "Internal"
...
type: LoadBalancer
loadBalancerIP: <your_static_internal_IP>

这将启动一个内部 LB 并将您的静态 IP 分配给它。您还可以在静态内部 IP 地址屏幕中检查新创建的负载均衡器现在正在使用新 IP。如果需要,您可以为其分配 Cloud DNS 记录。 此外,您可以在预订过程中选择“共享”IP 地址,这样它最多可供 50 个内部负载平衡器使用。

Assigning Static IP to Internal LB

Enabling Shared IP