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

流过昼夜 提交于 2020-01-04 05:37:10

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/53072209/how-to-get-around-specifying-host-header-to-access-services-pointed-by-ingress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!