Ingress intra-cluster Kubernetes communication

3/6/2018

I have an nginx ingress running in minikube (addon enabled) with a couple pods and services, the ingress has the following configuration:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx
spec:
  rules:
  - host: api.info
    http:
      paths:
      - backend:
          serviceName: api-service
          servicePort: 80
  - host: web.info
    http:
      paths:
      - backend:
          serviceName: web-service
          servicePort: 80

When I'm outside the cluster the following works fine:

curl --header 'Host: api.info' $(minikube ip)/health

But, when I'm inside the cluster, I would expect the containers to be able to talk to each other using their host names listed in my Ingress template. For example, I would expect the following to work, but it doesn't:

$ kubectl exec -it web-6c656c58d5-lpxsk /bin/bash
root@web-6c656c58d5-lpxsk:/web# curl api.info/health

Instead, it returns results from the actual api.info website, which I have no affiliation. First, can someone please confirm that this is suppose to work?

Thank you.

-- Nick
kube-dns
kubernetes
kubernetes-ingress
minikube
nginx

1 Answer

3/6/2018

Firstly, .info is a generic TLD, this makes DNS resolution messy.
Consider using a protected TLD or your own registered one e.g. api.example.com

You should edit your /etc/hosts with a line similar to:
<ip_address> api.info

or changing resolv.conf to prioritise your internal DNS.

-- stacksonstacks
Source: StackOverflow