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?
2
Answers
If you installed nginx-ingress using Helm you could:
Add
--service-node-port-range=80-32767
on/etc/kubernetes/manifests/kube-apiserver.yaml
.Set the service type to
NodePort
so that you can expose it publicly through port 80 and 443.nginx-ingress-controller
service to 80 and 443.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.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: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: