GKE上的单个LoadBalancer中有多个React应用

时间:2019-02-14 08:55:10

标签: reactjs docker kubernetes kubernetes-ingress google-kubernetes-engine

我想在一个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

Same与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应用?

1 个答案:

答案 0 :(得分:0)

是的,但是我认为您的第二条路径(路径:/ web2 / )将被忽略,因为第一个路径(路径:/ )会将/之后的所有内容路由到web1。尝试将第一条路线更改为(path:/ 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