【发布时间】: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