Enable Ingress to access NGINX default page with a custom domain name

Anuja Arosha
3 min readDec 6, 2021

Hi there 👋 In today’s post, we will try to put extra layer of load balancing for your small Kubernetes cluster where your services should not expose directly to outside but using Ingress API object.

If you remember my previous post, I have exposed the service in two ways and I’ve mentioned there are some more better ways of doing that. This is such an approach. What we are trying to do here is, provide a meaningful name for the service rather than localhost which we can access via web browser. To get that work done, we can use the Ingress Controller and it should be installed in your cluster. There are various types of Ingress Controllers and here we are using NGINX Ingress. I’ve used the Helm chart to install it with following command, but you can go through there official documentation if you need to get more idea of what you are dealing with.

helm upgrade --install ingress-nginx ingress-nginx --repo https://kubernetes.github.io/ingress-nginx --namespace ingress-nginx --create-namespace

Now you can update your values.yaml file like below to enable Ingress as well as provide a name for your web server host.

service:
type: LoadBalancer
port: 80
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
hosts:
- host: anujarosha.local
paths:
- path: /
backend:
serviceName: anujarosha.local
servicePort: 80
tls: []

If you compare the code with previous post, you may wonder, we could able to access the service with the type LoadBalancer . Yes, that is true and that is when the ingress.enabled = false . Now we have added an extra layer and the communication happens through this ingress layer. You can expose the service not only LoadBalancer but also NodePort . Since we do not need unnecessary changes, we will stick to the service type which we have already used.

Even after you deployed above modified helm chat, you will not be able to access the service using either localhost or anujarosha.local names using your web browser. localhost is not working since you have changed your service name to anujarosha.local and that particular name is not working since browser cannot identify that name. Now you need to edit your Mac /etc/hosts to point anujarosha.local to 127.0.0.1 or somehow else get the browser to hit the ingress LoadBalancer or NodePort when you browse to that URL. Once it is configured, now you can visit to your page and it will show like below.

That’s the end of this small post and we will enrich this cluster day by day. Keep in touch 🤓

--

--

Anuja Arosha

Native mobile application development enthusiasm. DevOps engineer.