Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kubernetes 在GKE上使用静态IP时,服务不会出现_Kubernetes_Google Cloud Platform_Google Kubernetes Engine - Fatal编程技术网

Kubernetes 在GKE上使用静态IP时,服务不会出现

Kubernetes 在GKE上使用静态IP时,服务不会出现,kubernetes,google-cloud-platform,google-kubernetes-engine,Kubernetes,Google Cloud Platform,Google Kubernetes Engine,我已经在我的GCP帐户上分配了一个静态IP。然后,我更新了应用程序的服务定义,以便在负载平衡器中使用它,如下所示: kind: Service apiVersion: v1 metadata: # Unique key of the Service instance name: my-app-service spec: ports: # Accept traffic sent to port 80 - name: http port: 80 t

我已经在我的GCP帐户上分配了一个静态IP。然后,我更新了应用程序的服务定义,以便在负载平衡器中使用它,如下所示:

kind: Service
apiVersion: v1
metadata:
  # Unique key of the Service instance
  name: my-app-service
spec:
  ports:
    # Accept traffic sent to port 80
    - name: http
      port: 80
      targetPort: 5000
  selector:
    # Loadbalance traffic across Pods matching
    # this label selector
    app: web
  # Create an HA proxy in the cloud provider
  # with an External IP address - *Only supported
  # by some cloud providers*
  type: LoadBalancer
  # Use the static IP allocated
  loadBalancerIP: 35.186.xxx.xxx
如果我把最后一行注释掉,让GKE分配一个短暂的公共IP,服务就会很好。你知道我做错了什么吗

根据回答中的建议,我创建了如下入口:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myapp
  annotations:
    kubernetes.io/ingress.global-static-ip-name: "myapp"
spec:
  backend:
    serviceName: my-app-service
    servicePort: 80
现在,我看到入口被分配了正确的静态IP。但是,我的服务也会被分配一个不同的公共IP。入口和服务未连接。如果我注释掉type:LoadBalancer行,则服务未分配公共IP,但入口仍不连接。当点击静态IP时,我会得到一个默认的后端404响应。我尝试过以不同的顺序创建服务和入口,但也没有任何帮助

如果我将其保留足够长的时间,静态IP会将流量路由到我的服务,但服务本身仍停留在外部IP分配中:

$ kubectl get service my-app-service
NAME                   CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
my-app-service          10.x.x.x        <pending>     80:31432/TCP   12m
您需要创建入口并使用kubernetes.io/ingres.global-static-ip-name:入口上的ip注释名称,以便kubernetes能够找到它


您可以在这里找到教程:

谢谢Ahmet。我创建了入口,我看到它成功链接到静态IP。然而,它似乎与我的服务没有联系。如果我将线路类型:LoadBalancer保留在那里,那么我的服务将从入口获得不同的IP。服务公共IP点击我的应用程序,ingress返回404。如果我注释掉type:LoadBalancer,那么我的服务没有外部IP,入口仍然在404上。有什么想法吗?@Raj,我建议你从头到尾地学习上面的教程,看看它是否有效。如果不是这样的话,我们可能应该向回购开放一个问题,并将其修复。最后,你问题的答案应该是我发布的链接。谢谢Ahmet。本教程公开了一个节点端口服务。我正在尝试负载平衡器服务。我明确地将上面的YAML更改为set type:NodePort,并且在命中外部IP时仍然得到404。我现在已经造成了这个缺陷:我认为外部IP最终会向我的服务发送流量,不管是它的LoadBalancer还是NodePort,只是开始这样做需要很长的时间,比如7-8分钟。静态IP最初返回HTTP 404,然后返回502,最后几分钟后,我看到了我的应用程序。我猜这是k8s/GKEbug@Raj这实际上是因为谷歌云正在全球所有边缘位置配置负载平衡器,这需要时间。GCP的负载均衡器不是区域性的,能够在世界各地的边缘位置接受流量,然后通过谷歌的内部网络转发到您的应用程序。这就是为什么gce入口系统实际工作大约需要5分钟。我也对自己感到困惑。