Ingress-Nginx-Controller 未能找到部署在 Google Cloud Platform 上的第二个服务
Ingress-Nginx-Controller failed to find the 2nd service deployed on Google Cloud Platform
我在 GCP 上部署了以下 2 项服务(内置于 Java):
mply6(服务1,监听GCP外部8080端口),对应URL:http://example.com/path1
gami6(服务2,监听GCP外部的8081端口),对应URL:http://example.com/path2
用于部署和公开服务 1 的 yaml:
kind: Service
apiVersion: v1
metadata:
name: mply6
spec:
selector:
app: mply6
ports:
- protocol: "TCP"
port: 80
targetPort: 8080
type: LoadBalancer
loadBalancerIP: "35.223.241.9"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mply6
spec:
replicas: 1
selector:
matchLabels:
app: mply6
template:
metadata:
labels:
app: mply6
spec:
containers:
- name: mply6
image: gcr.io/mply6-271000/mply6:latest
ports:
- containerPort: 8080
用于部署和公开服务 2 的 yaml:
kind: Service
apiVersion: v1
metadata:
name: gami6
spec:
selector:
app: gmai6
ports:
- protocol: "TCP"
port: 81
targetPort: 8081
type: LoadBalancer
loadBalancerIP: "35.223.241.9"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: gami6
spec:
replicas: 1
selector:
matchLabels:
app: gami6
template:
metadata:
labels:
app: gami6
spec:
containers:
- name: gami6
image: gcr.io/mply6-271000/gami6:latest
ports:
- containerPort: 8081
并且,用于创建 Ingress 资源的 yaml:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: basic-ingress
annotations:
kubernetes.io/ingress.global-static-ip-name: "35.223.241.9"
spec:
rules:
- http:
paths:
- path: /path1
backend:
serviceName: mply6
servicePort: 80
- path: /path2
backend:
serviceName: gami6
servicePort: 81
此外,'kubectl describe ingress basic-ingress'的结果:
Name: basic-ingress
Namespace: default
Address: 35.244.199.199
Default backend: default-http-backend:80 (10.60.1.4:8080)
Rules:
Host Path Backends
---- ---- --------
*
/multiplications/random mply6:80 (10.60.0.32:8080)
/results mply6:80 (10.60.0.32:8080)
/leaders gami6:81 (10.60.0.32:8081)
/stats gami6:81 (10.60.0.32:8081)
Annotations:
kubernetes.io/ingress.global-static-ip-name: 35.223.241.9
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal CREATE 35m nginx-ingress-controller Ingress default/basic-ingress
Warning Translate 21m loadbalancer-controller error while evaluating the ingress spec: could not find service "default/gami6"; could not find service"
default/gami6"
Warning Translate 6m17s (x34 over 77m) loadbalancer-controller error while evaluating the ingress spec: could not find port "8081" in service "default/gami6"; could no
t find port "8081" in service "default/gami6"
Normal CREATE 44s (x1153 over 22h) loadbalancer-controller ip: 35.244.199.199
Normal UPDATE 7s (x13 over 35m) nginx-ingress-controller Ingress default/basic-ingress
基本上我期望当我给出 URL 'http://example.com/path2' 时,Ingress-Nginx-Controller 会找到第二个服务 'gami6',但为什么是上面的错误信息:找不到服务 "default/gami6"? (http://example.com/path1可以在没有问题的情况下找到)
我无法对您上面的部署添加任何评论。但是,此部署与 http-balancer documentation
非常相似
我尝试了文档中提到的部署,并且能够实现您正在尝试做的事情。具有基于路径的负载均衡器路由请求。
首先,我注意到第二个服务 yaml 有一个拼写错误:
规格:
选择器:
app: gmai6 <-- 这应该是 gami6 吗?
要将 Google 的 Ingress 与多个后端一起使用,您可能需要使用“NodePort”而不是“LoadBalancer”来公开服务。您可以在本文档中找到相关信息:
https://cloud.google.com/kubernetes-engine/docs/concepts/ingress#multiple_backend_services
如果你想使用 nginx ingress controller,你应该遵循这个:指南:https://cloud.google.com/community/tutorials/nginx-ingress-gke
我在 GCP 上部署了以下 2 项服务(内置于 Java):
mply6(服务1,监听GCP外部8080端口),对应URL:http://example.com/path1
gami6(服务2,监听GCP外部的8081端口),对应URL:http://example.com/path2
用于部署和公开服务 1 的 yaml:
kind: Service
apiVersion: v1
metadata:
name: mply6
spec:
selector:
app: mply6
ports:
- protocol: "TCP"
port: 80
targetPort: 8080
type: LoadBalancer
loadBalancerIP: "35.223.241.9"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mply6
spec:
replicas: 1
selector:
matchLabels:
app: mply6
template:
metadata:
labels:
app: mply6
spec:
containers:
- name: mply6
image: gcr.io/mply6-271000/mply6:latest
ports:
- containerPort: 8080
用于部署和公开服务 2 的 yaml:
kind: Service
apiVersion: v1
metadata:
name: gami6
spec:
selector:
app: gmai6
ports:
- protocol: "TCP"
port: 81
targetPort: 8081
type: LoadBalancer
loadBalancerIP: "35.223.241.9"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: gami6
spec:
replicas: 1
selector:
matchLabels:
app: gami6
template:
metadata:
labels:
app: gami6
spec:
containers:
- name: gami6
image: gcr.io/mply6-271000/gami6:latest
ports:
- containerPort: 8081
并且,用于创建 Ingress 资源的 yaml:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: basic-ingress
annotations:
kubernetes.io/ingress.global-static-ip-name: "35.223.241.9"
spec:
rules:
- http:
paths:
- path: /path1
backend:
serviceName: mply6
servicePort: 80
- path: /path2
backend:
serviceName: gami6
servicePort: 81
此外,'kubectl describe ingress basic-ingress'的结果:
Name: basic-ingress
Namespace: default
Address: 35.244.199.199
Default backend: default-http-backend:80 (10.60.1.4:8080)
Rules:
Host Path Backends
---- ---- --------
*
/multiplications/random mply6:80 (10.60.0.32:8080)
/results mply6:80 (10.60.0.32:8080)
/leaders gami6:81 (10.60.0.32:8081)
/stats gami6:81 (10.60.0.32:8081)
Annotations:
kubernetes.io/ingress.global-static-ip-name: 35.223.241.9
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal CREATE 35m nginx-ingress-controller Ingress default/basic-ingress
Warning Translate 21m loadbalancer-controller error while evaluating the ingress spec: could not find service "default/gami6"; could not find service"
default/gami6"
Warning Translate 6m17s (x34 over 77m) loadbalancer-controller error while evaluating the ingress spec: could not find port "8081" in service "default/gami6"; could no
t find port "8081" in service "default/gami6"
Normal CREATE 44s (x1153 over 22h) loadbalancer-controller ip: 35.244.199.199
Normal UPDATE 7s (x13 over 35m) nginx-ingress-controller Ingress default/basic-ingress
基本上我期望当我给出 URL 'http://example.com/path2' 时,Ingress-Nginx-Controller 会找到第二个服务 'gami6',但为什么是上面的错误信息:找不到服务 "default/gami6"? (http://example.com/path1可以在没有问题的情况下找到)
我无法对您上面的部署添加任何评论。但是,此部署与 http-balancer documentation
非常相似我尝试了文档中提到的部署,并且能够实现您正在尝试做的事情。具有基于路径的负载均衡器路由请求。
首先,我注意到第二个服务 yaml 有一个拼写错误:
规格: 选择器: app: gmai6 <-- 这应该是 gami6 吗?
要将 Google 的 Ingress 与多个后端一起使用,您可能需要使用“NodePort”而不是“LoadBalancer”来公开服务。您可以在本文档中找到相关信息: https://cloud.google.com/kubernetes-engine/docs/concepts/ingress#multiple_backend_services
如果你想使用 nginx ingress controller,你应该遵循这个:指南:https://cloud.google.com/community/tutorials/nginx-ingress-gke