在GKE上为我的负载均衡器设置静态外部IP

jcg*_*582 8 kubernetes google-kubernetes-engine

我正在尝试为GKE上的负载均衡器设置静态外部IP,但没有运气.这是我的Kubernetes服务配置文件:

kind: Service
apiVersion: v1
metadata:
  name: myAppService
spec:
  selector:
    app: myApp
  ports:
  - protocol: TCP
    port: 3001
    targetPort: 3001
  type: LoadBalancer
  loadBalancerIP: *********
Run Code Online (Sandbox Code Playgroud)

这不起作用.我希望看到我的外部IP为*********,但它只是说待处理:

?  git:(master) kubectl get services
NAME         CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
kubernetes   *********    <none>        443/TCP          5m
myAppService   *********   <pending>     3001:30126/TCP   5m
Run Code Online (Sandbox Code Playgroud)

更多细节:

?  git:(master) kubectl describe services
Name:           kubernetes
Namespace:      default
Labels:         component=apiserver
            provider=kubernetes
Annotations:        <none>
Selector:       <none>
Type:           ClusterIP
IP:         *********
Port:           https   443/TCP
Endpoints:      *********
Session Affinity:   ClientIP
Events:         <none>


Name:           myAppService
Namespace:      default
Labels:         <none>
Annotations:        <none>
Selector:       app=myApp
Type:           LoadBalancer
IP:         *********
Port:           <unset> 3001/TCP
NodePort:       <unset> 30126/TCP
Endpoints:
Session Affinity:   None
Events:
  FirstSeen LastSeen    Count   From            SubObjectPath   Type        Reason              Message
  --------- --------    -----   ----            -------------   --------    ------              -------
  5m        20s     7   service-controller          Normal      CreatingLoadBalancer        Creating load balancer
  5m        19s     7   service-controller          Warning     CreatingLoadBalancerFailed  Error creating load balancer (will retry): Failed to create load balancer for service default/myAppService: Cannot EnsureLoadBalancer() with no hosts
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

chr*_*riz 7

这也让我陷入困境,我希望有人觉得这有帮助。

除了Dirk所说的,如果您碰巧保留了一个全局静态 IP 地址,而不是区域 IP 地址;您需要按照文档中的描述使用 Ingres:Configuring Domain Names with Static IP Addresses特别是步骤 2b。

所以基本上你保留静态IP gcloud compute addresses create helloweb-ip --global

并添加一个 Ingres:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: helloweb
# this is where you you add your reserved ip
  annotations:
    kubernetes.io/ingress.global-static-ip-name: helloweb-ip 
  labels:
    app: hello
spec:
  backend:
    serviceName: helloweb-backend
    servicePort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: helloweb-backend
  labels:
    app: hello
spec:
  type: NodePort
  selector:
    app: hello
    tier: web
  ports:
  - port: 8080
    targetPort: 8080
Run Code Online (Sandbox Code Playgroud)

如果您在步骤 2a 下选择类型“LoadBalancer”,该文档还描述了如何分配静态 IP。


Dir*_*ski 6

我遇到了同样的问题,但仔细阅读文档后,结果发现我只是错误地保留了静态 IP。类型服务LoadBalancer创建一个网络负载均衡器,它是区域性的。因此,您保留的静态 IP 地址也需要是区域性的(在集群的区域内)。当我改用这个解决方案时,一切对我来说都很好......

  • 你是如何做出改变的?可以分享一下步骤吗? (3认同)