How To Install and Setup Nginx Controller On A Cluster

Nwokolo Emmanuel
4 min readMay 11, 2023

Hey! Welcome to another edition of my Kubernetes series.

In this edition, you will be learning how to create an Nginx controller on your cluster.

The Nginx controller is like a load balancer that helps you route traffic to services in a cluster.

The Nginx controller has some other functions, but we will use it as a Load balancer for this project.

prerequisite:

  • A cluster running
  • An Ubuntu machine
  • Helm Installed
  • Terraform installed
  • Kubectl installed
  • AWS CLI installed

To make things easier, follow this link HERE to get the script I wrote that helps you install all these tools on your machine.

I have also put a link HERE, that will help to spin up a Virtual Machine on DigitalOcean or any other cloud provider.

And If you have gotten all these setups, let’s dive into our main topic!

PROVIDERS.TF FILE

Just like we did in the Prometheus section HERE, We will also create a “provider.tf” file to help define the providers.

There are three required providers: Helm, Kubernetes, and Kubectl, for this section also.

Also, as seen previously, we will include a data resource that will reference our cluster to get information that will help us to configure the Kubernetes, Helm, and Kubectl providers.

The config_path defines the default path for the kube-config file. You can make the needed changes to it.

For example, where you see ClusterName, remove it and insert the name of your cluster.

Where ClusteName_auth is present, you should only remove the ClusterName and put yours.

But do not change the _auth

EXAMPLE:

demo_auth

NGINX-HELM.TF

As with the Prometheus installation blog, we will also have a Helm file written with Terraform.

This helm file helps us with the resources to install the nginx-controller.

This file will help us define the resources to install the nginx-controller. It will also help us create a namespace.

You can change the name of the namespace if you want.

Also, we need to set values for the helm file (through the values.yaml file) to configure the nginx-controller when created.

These are default values from Nginx.

However, you can refactor the file as your project requires, which should only be done when you know what you are doing.

NOTE:

To set up the values.yaml file, create a new file, and name it “values.yaml”. Go to this GitHub link HERE, copy the contents of its values.yaml file, and paste it into yours.

And now, we are done with the Nginx controller’s configuration. We can then run the scripts with the commands below:

$ terraform init

This command helps to initialize terraform in our project’s directory.

terraform apply --auto-approve

This command runs your terraform script, and when the script has run successfully, you can type the following command on the terminal:

$ kubectl get namespace

This helps to see the current namespaces, and you should see a namespace called Nginx-controller.

$ kubect get svc -n nginx-controller

This command runs to see the services in the Nginx controller namespace.

After executing the command above, you should see an IP address or a DNS name, depending on where your infrastructure is running.

This DNS name will be used for each of our ingress rules.

You are going to see how this works in the coming series.

And with this, you have successfully deployed your Nginx controller.

Congratulations on your progress!!!

Resources

NOTICE

There is a platform called THE CLOUD TOP G MASTERMIND where you can learn more about becoming a Cloud Engineer, the tools you need to build your projects, and getting your dream job.

You can get more details by clicking this LINK.

see you soon!

NOTE: If you have any questions or want to add to this blog, you can send me an E-mail. And I reply faster to people that subscribe to my newsletter!!

Conclusion

If you loved this blog post, please, give it a like, comment, and don’t forget to click the follow button.

And if you would love to get an update on the two exciting blogs I will be posting this week, then you should sign up for my newsletter right here!!

--

--

Nwokolo Emmanuel
Nwokolo Emmanuel

Written by Nwokolo Emmanuel

I am a Cloud Engineer, I love sharing easy solutions to problems that I found difficult. Interested in Open Source | twitter: twitter.com/CloudTopG