Im struggling with the ingress configuration that will allow accessibility from two different paths to services which are deployed on different namespaces.
1# Ingress:
# Source: deployment/templates/ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: portal-api
labels:
helm.sh/chart: deployment-0.1.0
app.kubernetes.io/name: deployment
app.kubernetes.io/instance: portal-api
app.kubernetes.io/version: "0.0.1"
app.kubernetes.io/managed-by: Helm
annotations:
certmanager.k8s.io/acme-challenge-type: http01
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
kuberentes.io/tls-acme: "true"
kubernetes.io/ingress.class: nginx
spec:
tls:
- hosts:
- "example.com"
secretName: portal-certificate
rules:
- host: "example.com"
http:
paths:
- path: /api/rest/(.*)
backend:
serviceName: portal-api
servicePort: 80
# Source: deployment/templates/ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: portal-ui
labels:
helm.sh/chart: deployment-0.1.0
app.kubernetes.io/name: deployment
app.kubernetes.io/instance: portal-ui
app.kubernetes.io/version: "0.0.1"
app.kubernetes.io/managed-by: Helm
annotations:
certmanager.k8s.io/acme-challenge-type: http01
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
tls:
- hosts:
- "example.com"
secretName: portal-certificate
rules:
- host: "example.com"
http:
paths:
- path: /(.*)
backend:
serviceName: portal-ui
servicePort: 80
Routing for path example.com - works, its redirect to portal-ui. Routing for path example.com/api/rest/(something) - doesnt works, its redirect to portal-ui service.
I think that It will works on the same namespace... But i need two namespaces for each service.
As @Arghya Sadhu mentioned
Ingress and its corresponding service need to be in same namespace otherwise ingress cannot discover endpoints from the service.
There is a github issue opened since 2015 and there is still discuss how to make it work.
For now it´s either to create ingress in the same namespace
Example made by github issue member @aledbf
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: component1
namespace: component1
spec:
rules:
- host: domain.com
http:
paths:
- backend:
serviceName: component1
servicePort: 80
path: /component1
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: component2
namespace: component2
spec:
rules:
- host: domain.com
http:
paths:
- backend:
serviceName: component2
servicePort: 80
path: /component2
OR
You could try workaround made by github issue member @chestack
my workaround:
serviceA in namespaceA
create serviceB in namespaceB
spec:
...
type: ExtertalName
externalName: serviceA.namespaceA.svc.cluster.local
add ingress rule into ingressB in namespaceB
- path: /****
backend:
serviceName: serviceB
servicePort: ***
Ingress and its corresponding service need to be in same namespace otherwise ingress cannot discover endpoints from the service. So create ingress1, service1 in namespace1 and ingress2, service2 in namespace2.