【问题标题】:Ingress-Nginx-Controller failed to find the 2nd service deployed on Google Cloud PlatformIngress-Nginx-Controller 找不到部署在 Google Cloud Platform 上的第二个服务
【发布时间】:2020-03-15 03:03:56
【问题描述】:

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

部署和暴露服务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',但为什么上面的错误消息:找不到服务“默认/游戏6”? (http://example.com/path1在没有问题的情况下可以找到)

【问题讨论】:

    标签: service google-cloud-platform nginx-ingress


    【解决方案1】:

    首先,我注意到第二个服务 yaml 有一个错字:

    规格: 选择器: app: gmai6

    要将 Google 的 Ingress 与多个后端一起使用,您可能需要使用“NodePort”而不是“LoadBalancer”来公开服务。您可以在此文档中找到相关信息: https://cloud.google.com/kubernetes-engine/docs/concepts/ingress#multiple_backend_services

    如果你想使用 nginx 入口控制器,你应该遵循这个:指南:https://cloud.google.com/community/tutorials/nginx-ingress-gke

    【讨论】:

    • 感谢卢卡斯发现错字(我的愚蠢错误)!这是根本原因,导致服务gami6无法连接到运行图像文件的pod。使用 NodePort 暴露多个后端服务也是一个好主意,将尝试一下!再次感谢!
    【解决方案2】:

    我无法对您上面的部署添加任何评论。然而这个部署与http-balancer documentation 非常相似

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-06
      • 2020-11-14
      • 2019-02-06
      • 2020-12-05
      相关资源
      最近更新 更多