0
votes

I am using Kubernetes in minikube on Ubuntu 18.04 with ingress add-on enabled. I want my NextJS service to communicate to my Express Service connected via ingress server by making request only via Ingress controller. So when I use cross namespace communication it doesn't work as illustrated in the tutorial presented. Since ingress-nginx in minikube runs on kube-system namespace.

$ kubectl get service -n kube-system

NAME                                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                  AGE
ingress-nginx-controller-admission   ClusterIP   10.103.20.47   none          443/TCP                  15d
kube-dns                             ClusterIP   10.96.0.10     none          53/UDP,53/TCP,9153/TCP   36d

The services that I am running

$ kubectl get services
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)     AGE
exp-mongo-srv    ClusterIP   10.103.255.125   <none>        27017/TCP   42s
exp-srv          ClusterIP   10.103.118.45    <none>        3000/TCP    42s
next-srv         ClusterIP   10.108.158.184   <none>        3000/TCP    39s

Expected request url was: http://ingress-nginx.ingress-nginx.svc.cluster.local(Communication through nginx)
But instead I have to go through http://exp-srv:3000 (Which is direct communication between services)

2

2 Answers

1
votes

It is so simple to do it

you have added wrong namespace name

instead of

http://ingress-nginx.ingress-nginx.svc.cluster.local

it should be

http://ingress-nginx.kube-system.svc.cluster.local

if you want to use it as host and want to resolve it

If you are using ambassador to any other API gateway for service located in another namespace it's always suggested to use :

            Use : <service name>
            Use : <service.name>.<namespace name>
            Not : <service.name>.<namespace name>.svc.cluster.local

it will be like : servicename.namespacename.svc.cluster.local

this will send request to a particular service inside the namespace you have mention.

example:

kind: Service
apiVersion: v1
metadata:
  name: service
spec:
  type: ExternalName
  externalName: <servicename>.<namespace>.svc.cluster.local

Here replace the <servicename> and <namespace> with the appropriate value.

In Kubernetes, namespaces are used to create virtual environment but all are connect with each other.

0
votes

Just stumbled on this. I think by default the service ingress-nginx-controller-admission which is a ClusterIP only has 443 which is HTTPS port exposed and hence it can't resolve it. What you need to do to solve this is expose a new clusterIP service.

kubectl expose deployment ingress-nginx-controller --target-port=80 --type=ClusterIP -n kube-system