我想在一个kubernetes集群中部署2个不同的React应用(作为Nodeport服务公开)。将它们暴露在单独的入口上工作正常,我看到了每个页面的反应页面。即用于服务Web1

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: fanout-ingress-1
spec:
  rules:
  - http:
      paths:
      - path: /*
        backend:
          serviceName: web1
          servicePort: 5000

同样适用于serviceName: web2。但是,尝试将两者合并为扇出入口仅显示其中一项服务(web1):
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: fanout-ingress
  annotations:
    kubernetes.io/ingress.class: "gce"
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /*
        backend:
          serviceName: web1
          servicePort: 5000
      - path: /web2/*
        backend:
          serviceName: web2
          servicePort: 5000

是否可以在单个Ingress上公开2个React应用?

最佳答案

是的,这是可能的,但是我认为您的第二条路径(路径:/ web2 /)将被忽略,因为第一个路径(路径:/)会将/之后的所有内容路由到web1。尝试将第一条路线更改为(路径:/ web1 / *)。像这样:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: fanout-ingress
  annotations:
    kubernetes.io/ingress.class: "gce"
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /web1/*
        backend:
          serviceName: web1
          servicePort: 5000
      - path: /web2/*
        backend:
          serviceName: web2
          servicePort: 5000

09-04 21:34