简体   繁体   中英

Unable to use ingress-nginx for routing on Ubuntu 18.04

I was trying to use Kubernetes to set up a service locally. I am using ingress-nginx for routing. I am using Ubuntu 18.04. This is my ingress.yaml file:

apiVersion: extensions/v1beta1
kind: Ingress
metadata: 
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: 'true'
spec: 
  rules:
    - host: ecommerce.dev
      http:   
        paths: 
          - path: /api/users/?(.*) 
            backend: 
              serviceName: auth-srv
              servicePort: 3000

Also, I mapped this in my /etc/hosts/ file:

127.0.0.1   localhost
127.0.1.1   TALHA

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

127.0.0.1 ecommerce.dev

When I try to reach 'ecommerce.dev' from my browser, I am unable to access it as it says 'Site can not be reached'. Can someone please help me about it?

I saw you mentioned you are using minikube with nginx ingress addon.

This information helps a lot. Try not to skip this kind of information in future. I was assuming that by saying "I was trying to use Kubernetes to set up a service locally" you mean that you run baremetal k8s.

Minikube is most probably running in a VM and this is why you cannot access it.

Running minikube ip gives you the IP address of a VM:

$ minikube ip
192.168.39.67

Your ip may be different so don't use my IP, check what IP you got assigned.

Now that you have the IP of a minikube VM, use it in /etc/hosts . In my case it looks like following:

192.168.39.67 ecommerce.dev

If you installed nginx-ingress using Helm you could:

  1. Add --service-node-port-range=80-32767 on /etc/kubernetes/manifests/kube-apiserver.yaml .

  2. Set the service type to NodePort so that you can expose it publicly through port 80 and 443.

kubectl patch svc ingress-nginx-controller -p '{"spec": {"type": "NodePort"}}'
  1. Change the default generated ports of the nginx-ingress-controller service to 80 and 443.
kubectl patch svc ingress-nginx-controller -p '{"spec": {"ports": [{"name": "http", "nodePort": 80, "port": 80, "protocol": "TCP", "targetPort": "http"}, {"name": "https", "nodePort": 443, "port": 443, "protocol": "TCP", "targetPort": "https"}]}}'

This steps would only open the ports 80 and 443 of your nginx-ingress-controller service. If it does not solve your problem then it's probably related to your proxy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM