How to get access from localhost:8080 to service using nginx-ingress?

1/8/2020

I want to access nginx on pod using localhost:8080 as uri, not minikube ip

  apiVersion: v1
    kind: Service
    metadata:
      name: nginx-service
    spec:
      selector:
        app: webserver
      ports:
        - port: 80
          targetPort: 80

enter image description here

enter image description here

-- Igor Smirnov
kubernetes

1 Answer

1/8/2020

I guess this is for development/debug purpose.
So if you can't use port-forward option as @arghya-sadhu suggested, then you'll just have to map your domain to your ip.

I can see that's what you're trying to do in your nginx deployment with those lines :

spec:
  hostAliases:
  - ip: 192.168.99.101
    hostnames:
    - localhost

However, this will not affect your host. In order to map localhost to the minikube ip, you'll have to edit your /etc/hosts file. Below is the line you need to add :

192.168.99.101    localhost
#127.0.0.1    localhost <-- this line needs to be commented

Be sure to comment the existing line with localhost

-- Marc ABOUCHACRA
Source: StackOverflow