【发布时间】:2017-04-15 07:22:02
【问题描述】:
我已在我的 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,服务就会正常运行。任何想法我做错了什么?
根据回答中的建议,我创建了一个Ingress,如下所示:
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
现在,我看到 Ingress 被分配了正确的静态 IP。但是,我的 Service 也被分配了一个(不同的)公共 IP。 Ingress 和 Service 未连接。如果我注释掉 type: LoadBalancer 行,Service 没有分配公共 IP,但 Ingress 仍然无法连接。访问静态 IP 时,我收到 default backend - 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 google-cloud-platform google-kubernetes-engine