【问题标题】:GKE - how to attach static ip to internal load balancerGKE - 如何将静态 IP 附加到内部负载均衡器
【发布时间】:2020-02-05 10:36:45
【问题描述】:

我想将服务从一个 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: {}

我还是无法连接

【问题讨论】:

  • 创建的 GCP 负载均衡器是否与您的规范中反映的 IP 相同?
  • 事实上,如果你的状态一直是空白状态,就说明没有分配IP。 IP当前是否保留为静态?如果是这样,那将行不通。 IP 需要可用,如果您将其保留为静态,则 GCP 平台不会将其视为可用。
  • 是的,我将 ip 保留为静态的,我认为这就是全部线索。那么我应该把什么样的 ip 作为 loadBalancerIP 让它工作呢?从我的范围中随机选择一些?目前它将我的外部 ip 描述为挂起的 ``` NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ilb-service LoadBalancer 11.11.1.111 80:31894/TCP 28m ```
  • 是的,只需使用子网中未使用的部分即可。您甚至可以释放当前保留的 ip 并使用它。这是一个常见错误,在 gcp 文档中并不清楚它是如何工作的。这专门用于内部负载平衡器
  • 感谢它现在可以使用。但我希望能够通过某种 dns 名称而不是 ip 从一个集群连接到负载均衡器。在我读过的文档中,保留静态 ip 并添加 dns 记录是一种解决方案。如何在您的方法中通过 dns 名称访问负载均衡器?

标签: google-cloud-platform google-kubernetes-engine google-cloud-networking


【解决方案1】:

2021 年 11 月更新

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

  1. 转到 VPC 网络 -> 选择您的 VPC -> 静态内部 IP 地址
  2. 单击保留静态地址,然后为您的 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

【讨论】:

    猜你喜欢
    • 2020-02-20
    • 2018-08-01
    • 1970-01-01
    • 2019-06-22
    • 2017-03-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-14
    • 2022-06-23
    相关资源
    最近更新 更多