Ingress is the application load balancer in the Kubernetes. Ingress is used to manage the external access to the services in a cluster.
Build the docker images using Dockerfiles in the services/ folder.
$ docker build -t cankush625/mailapp:v1 ./services/mail/.
$ docker build -t cankush625/searchapp:v1 ./services/search/.
$ kubectl create deployment mail --image=cankush625/mailapp:v1
$ kubectl create deployment search --image=cankush625/searchapp:v1
$ kubectl expose deploy mail --port=80 --type=NodePort
$ kubectl expose deploy search --port=80 --type=NodePort
We always provide host name or domain name to the Ingress Controller. So, either we required the real domain name or we can create a local entry for domain name/host name in the local host file.
In linux, the host file is located at /etc/hosts
and in windows, the host file is located at C:\Windows\System32\drivers\etc\hosts
.
In this demo, I will use www.example.com as a domain name(host name). And as I'm running the k8s cluster using minikube, the minikube is running on IP 192.168.99.100.
So, go to the host files mentioned above and add the following line.
192.168.99.100 www.example.com
For creating the Ingress rule, run one of the above configuration file depending on your kuberntes version.
$ kubectl create -f ingress_resource.yml
Now, we can access the mail and search services using the path we had added in the ingress rule.
$ curl www.example.com:80/mail
$ curl www.example.com:80/search