简体   繁体   中英

react installation in nginx vs K8s ingress vs istio gateway

I have a react application installed in a nginx and then an express.js server for the backend connected to a mysql. When a client makes a petition to the x.com/ the default.conf from nginx indicates to pick the files from the local /var/www/build folder, when the path is x.com/api the nginx redirect the call to the express.js server.

upstream client {
    server client:3000;
}

upstream api {
    server api:3001;
}

server {
    listen 80;

    #location / {
    #    proxy_pass http://client;
    #}
    location / {
        root /var/www/build;
        try_files $uri /index.html;
    }

    # location /sockjs-node {
    #     proxy_pass http://client;
    #     proxy_http_version 1.1;
    #     proxy_set_header Upgrade $http_upgrade;
    #     proxy_set_header Connection "Upgrade";
    # }

    location /sockjs-node {
        root /var/www/build;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }
    
    location /api {
        rewrite /api/(.*) /$1 break;
        proxy_pass http://api;
    }
}

My question is that now that I put all into containers and in a K8s cluster, I have used an Istio gateway. But in my configuration is just past all traffic in the gateway to the nginx container.

---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: rproxygw
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: rproxy
spec:
  hosts:
  - "*"
  gateways:
  - rproxygw
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        host: rproxy
        port:
          number: 80

What then would be better now that all is on K8s cluster with Istio? to just redirect the x.com/api from the gateway?

Is there any way to install the react static files into the Istio gateway and get rid of the nginx proxy?

How about getting rid of the nginx as reverse proxy and just use the Istio gateway and to install the react app into another express server or just reuse the express server in which the backend is running to install as well the react static files?

what option would perform best in terms of latency?

Is there any way to install the react static files into the Istio gateway

No. It only forwards requests to Kube.netes Services.

Any of the various approaches you describe will work fine. Nginx is fairly efficient; all else being equal fewer hops are better. If it turns out your application is easier to manage keeping the Nginx reverse proxy, there's nothing wrong with keeping it. If your front- and back-end code are in the same repository and it's straightforward to build them into the same container image then similarly there's nothing wrong with having a single process serving both parts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM