I have a Mongo, Express, React Node app that is currently deployed in a microk8s pod. I am trying to setup Ingress for the app. The express server is setup to serve the react with express.static like below
app.use(express.static('DemoApp/build'));
app.get('*', function(req, res, next) {
res.sendFile(path.resolve(__dirname, 'DemoApp', 'build', 'index.html'));
});
Everything works fine when I navigate to the ip:port of the kubernetes cluster and even everything works fine when I navigate to the FQDN for the ingress host but as soon as I add a path to the ingress then the app only shows a white screen. One note, my kubernetes node and workstations are all running inside an internal private network. I am not trying to expose anything outside of that. I have tried to follow the step provided in this post ( ReactJS app displays whitescreen using Kubernetes Ingress ) but it has not fixed the issue. I have the built in ingress controller enabled for microk8s.
Below is the YAML I am using for ingress that doesnt work
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: demo-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
namespace: default
spec:
rules:
- host: apps.sst.com
http:
paths:
- path: /demo(/|$)(.*)
backend:
serviceName: mern-demo
servicePort: 4000
Here is the YAML for ingress that does work
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: demo-ingress
annotations:
namespace: default
spec:
rules:
- host: apps.sst.com
http:
paths:
- path:
backend:
serviceName: mern-demo
servicePort: 4000
One other note is that my app is using react router. Based on further research I am wondering if this affects things at all.
Any help would be greatly appreciated. Thanks
rewrite-target annotation which was used in your YAML
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
works only for Nginx Ingress . As you are using your default ingress
it will not work. You would need to install it manually as it is mentioned here .
Now depends on your env if it's local or cloud you would need to configure MetalLB . For more details you can check this thread .
There was also similar StackOverflow question regarding Nginx Ingress
issue on MicroK8s
, you can read about it in this SO thread .
However, do you need to use rewrite? You cannot use multiple paths
and default backend
? Something like this:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: my-ingress
spec:
backend:
serviceName: hello-world
servicePort: 60000
rules:
- http:
paths:
- path: /world
backend:
serviceName: hello-world
servicePort: 60000
- path: /kube
backend:
serviceName: hello-kubernetes
servicePort: 80
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.