How to get around specifying "Host" header to access services pointed by Ingress controllers?

10/30/2018

My ingress controller is working and I am able to access the service outside the cluster using http://(externalIP)/path using an HTTP GET request from a RestClient. However, I had to specify the "Host" header with value = "host" (value of my Ingress Resource) for this to work. Because of this, I am not able to hit http://(externalIP)/path from my web browser. Is there any way I can enable access from my external web browser without having to specify "Host" in the request header?

Ingress Resource :

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  namespace: ingress-nginx
  annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: master1.saas.com
    http:
      paths:
      - backend:
          serviceName: gen-devops
          servicePort: 10311
        path: /*

Ingress Service :

apiVersion: v1
kind: Service
metadata:
  name: ingress-nginx
 namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  type: NodePort
  ports:
    - name: http
      port: 80
      targetPort: 80
      protocol: TCP
    - name: https
      port: 443
      targetPort: 443
      protocol: TCP
   externalIPs:
    - 172.16.32.85

  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
-- user1722908
kube-dns
kubernetes
kubernetes-ingress
nginx-ingress
nginx-reverse-proxy

1 Answer

10/30/2018

I assume you want to use this for testing.

If you are using any *nix flavor OS (MacOS, Linux) you can add an entry to your /etc/hosts file, something like this:

172.16.32.85 master1.saas.com

If you are using any Windows box you can add the same entry in C:\Windows\System32\Drivers\etc\hosts

-- Rico
Source: StackOverflow