I am trying to create an ingress resource as below, my issue is my service1 and service2 are located in a different namespace in kubernetes. so in order my ingress resource to connect both the services I am providing as service2.<namespace>
. but I am not able to create as (.) is not allowed. How can I point my service.2 present in a different namespace?
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
namespace: default
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/add-base-url: "true"
spec:
rules:
- host: test.com
http:
paths:
- path: "/"
backend:
serviceName: service1
servicePort: 1000
- path: "/test"
backend:
serviceName: service2.test
servicePort: 2000
You can solve it in two ways:
You can create another Ingress
resource in test
namespace for the /test
path.
If you are not running on GKE, you can also create a Service
of type ExternalName
in current namespace which maps to service2
service in test
namespace. Then you can use the name service2
to refer to service2.test
kind: Service
apiVersion: v1
metadata:
name: service2
namespace: default
spec:
type: ExternalName
externalName: service2.test.svc.cluster.local
ports:
- port: 2000