service - Ingress-Nginx-Controller 找不到部署在 Google Cloud Platform 上的第二个服务
问题描述
我在 GCP 上部署了以下 2 个服务(用 Java 构建):
mply6(服务1,监听GCP外部8080端口),对应URL:http ://example.com/path1
gami6(服务2,监听GCP外部的8081端口),对应URL:http ://example.com/path2
部署和公开服务的 yaml 1:
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',但是为什么上面的错误消息:找不到服务“默认/gami6”?(http://example.com/path1在没有问题的情况下可以找到)
解决方案
我无法对您上面的部署添加任何评论。但是,此部署与http-balancer 文档非常相似
我尝试了文档中提到的部署,并且能够实现您想要做的事情。具有基于路径的负载均衡器路由请求。
推荐阅读
- ios - 是否多次完成导航加载
- python-3.x - 如何在 pandas 数据框中的多个列上执行分组并在 python 中使用 fbProphet 预测未来值?
- c - 我需要帮助在 C 中从中缀转换为后缀
- laravel - Laravel:REJECT ROUTE 未定义但存在于 web.php 中
- php - PHP 代码没有从数据库中获取正确的值
- sql - 将值插入表中
- c# - 数据未显示在 C# 和 SQL Server 中的复选框上
- git - 强制 git 识别文件已重命名,更改后
- java - 根据导航目的地更新 ActionBar 菜单
- c# - 如何在Unity中将一些都在同一平面上的3D点的维度降低到2D?