How to connect nginx frontend to aspnetcore backend on k8s?

4/3/2018

how are you?, i´m having trouble with the connection between my frontend and backend deployments in kubernetes. Inside of my Nginx frontend I can:

curl http://abphost

But in the browser I'm getting:

net::ERR_NAME_NOT_RESOLVED

  • abphost is a ClusterIP service.
  • I´m using a NodePort service to access my nginx frontend.
-- tnovau
backend
frontend
kubernetes
nginx
service

1 Answer

4/5/2018

But in the browser I'm getting:

Sure, that's because the cluster has its own DNS server, called kube-dns that is designed to resolve things inside the cluster that would not ordinarily have any meaning whatsoever outside the cluster.

It is an improper expectation to think that http://my-service.my-ns.svc.cluster.local will work anywhere that doesn't have kube-dns's Servce IP as its DNS resolver.

If you want to access the backend service, there are two tricks to do that: create a 2nd Service of type: NodePort that points to the backend, and the point your browser at that new NodePort's port, or

By far the more reasonable and scalable solution is to use an Ingress controller to surface as many Services as you wish, using the same nginx virtual-hosting that you are likely already familiar with using. That way you only expend one NodePort but can expose almost infinite Services, and have very, very fine grained control over the manner in which those Services are exposed -- something much harder to do using just type: NodePort.

-- mdaniel
Source: StackOverflow