首页 > 解决方案 > Ingress-Nginx-Controller 找不到部署在 Google Cloud Platform 上的第二个服务

问题描述

我在 GCP 上部署了以下 2 个服务(用 Java 构建):

部署和公开服务的 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在没有问题的情况下可以找到)

标签: servicegoogle-cloud-platformnginx-ingress

解决方案


我无法对您上面的部署添加任何评论。但是,此部署与http-balancer 文档非常相似

我尝试了文档中提到的部署,并且能够实现您想要做的事情。具有基于路径的负载均衡器路由请求。


推荐阅读