I have 2 namespaces called dev
and stage
in both namespaces I have similar setups. In both namespaces I have service called frontend.
I wanted to set up an ingress for this. I set up ingress in both namespaces with the following config:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress
spec:
rules:
- host: dev.myapp.io
http:
paths:
- backend:
serviceName: frontend
servicePort: 80
In the stage just changed the host to stage.myapp.io
. It is not working for one of the namespaces. Does my approach is correct? Or I need to set up ingress in another namepace (Kube-system maybe) and point paths in the same ingress?
PS: If I change service names and keep it different, 2 ingress works just fine but I want to set up services with same namespace, as it simplifies my other deployments.
Your are supposed to include the namespace annotation to your Ingress. Considering it, your yaml files should look like this:
Dev:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress-dev
namespace: dev
spec:
rules:
- host: dev.myapp.io
http:
paths:
- backend:
serviceName: frontend
servicePort: 80
Stage:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress-stage
namespace: stage
spec:
rules:
- host: stage.myapp.io
http:
paths:
- backend:
serviceName: frontend
servicePort: 80