How to Setup an NGINX Kubernetes Ingress Controller

choubertsprojects

VPN offers!

1. NordVPN

2. Surfshark

3. ExpressVPN

NGINX is a popular web server with extensive support for HTTP, HTTPS, and SSL. It’s designed to handle the traffic flow of websites at large scale while still being easy to use. One feature that NGINX has in particular is its ability to route requests based on content types or locations – meaning it can help you group certain requests together during your load balancing process if needed.

The “nginx ingress controller” is a Kubernetes Ingress Controller. It’s used to setup an NGINX ingress controller with the help of Helm. The process is simple and can be done in just a few minutes.

How to Setup an NGINX Kubernetes Ingress Controller

Configuring an ingress with an ingress controller is the ideal approach for managing numerous incoming services inside a Kubernetes cluster from outside the cluster.

Networking rules such as incoming TCP connections and routing are implemented by ingress controllers. NGINX, a sophisticated web service that operates as an interface between a cluster and the outside world, is one of the most widely used ingress controllers.

You’ll learn how to set up an NGINX Kubernetes Ingress Controller step by step in this article. Are you still interested?

Let’s get started!

Prerequisites

This article will be a step-by-step guide. To follow along, make sure you have the following items:

How to Install Kubernetes on an Ubuntu Machine is a related article.

What is an Ingress Controller, and how does it work?

You have many alternatives for exposing your application from outside the Kubernetes cluster, including NodePort, Load balancer, and Ingress.

  • The application is exposed on a port across all of your nodes when you use a Kubernetes service of type NodePort.
  • Use a LoadBalancer Kubernetes service to construct an external load balancer linked to a specified IP address and pointing to a Kubernetes service in your cluster.
  • When you need to communicate with and route traffic to various Kubernetes services from outside the Kubernetes cluster, use the Ingress Kubernetes service type.

Ingress is made up of two main parts: the ingress controller and the ingress resources.

  • All of the rules and HTTP/HTTPS routing connections from outside the cluster to the Kubernetes services are defined by ingress resources.
  • The ingress controller takes traffic via an ingress-managed load balancer and then directs it to the configured Kubernetes services depending on the ingress resources’ rules.

The client connects to Kubernetes services in the Kubernetes cluster through an ingress managed load balancer and an Ingress controller utilizing Ingress resources that comprise a set of rules, as seen in the figure below.

Ingress Service and Ingress Controller are used to receive client requests from outside the cluster. Ingress Service and Ingress Controller are used to receive client requests from outside the cluster.

Using Helm to install NGINX Ingress Controller

Let’s get started with some practical examples. To begin, create an ingress controller that establishes rules for network access from outside the cluster using ingress resources. Helm, a popular package management, will be used to install this ingress controller.

1. Connect to your Kubernetes cluster using your chosen SSH client.

2. Make a folder called /nginx-ingress-controller and move the working directory to it (cd). All of the configuration files you’ll be dealing with will be in this folder.

mkdir /nginx-ingress-controller/nginx-ingress-controller/nginx-ingress-controller/nginx nginx-ingress-controller/cd

3. Next, use the curl command to add an official stable helm repository. This step is required since the helm repository is not included in the /etc/apt/sources.list file by default. This step ensures Helm can locate the ingress controller package if it is required.

curl get-helm-3 https://raw.githubusercontent.com/helm/helm/master/scripts/

An official stable helm repository has been added. An official stable helm repository has been added.

Getting Started With Kubernetes Helm is a related article.

4. Now that Helm is installed on your system, use the helm repo add command to add the NGINX ingress controller repository. The charts relating to ingress-nginx that will be utilized for the installation of the ingress controller will be stored in the NGINX ingress controller repository.

https://kubernetes.github.io/ingress-nginx/helm-repo-ingress-nginx/helm-repo-ingress-nginx/helm-repo-ingress-nginx/helm-repo-ingress-

The fact that ingress-nginx has been added to your repository demonstrates that the ingress-nginx repository has been successfully added to the helm.

5. Finally, execute the helm repo update command to update Helm. The Helm repo update command gets information about accessible charts from chart repositories and updates it locally.

6. Finally, execute the helm install command to install the NGINX ingress controller. Using the chart, the Helm install command installs an ingress controller (ingress-nginx). The value of the controller is set using —set. On the command line, set publishService.enabled to true.

—set controller.publishService.enabled=true helm install nginx-ingress ingress-nginx/ingress-nginx

The NGINX ingress controller is installed. The NGINX ingress controller is installed.

7. Run the kubectl get all command to see whether the NGINX ingress controller is installed. The Kubectl command will show you all of the cluster’s information.

After running the command successfully, you’ll see that the There are two Kubernetes objects in the ingress controller.: a pod and a service.

  • By polling the /ingress endpoint, the pod executes the controller to get changes from the Ingress Resources.
  • External traffic will come to the controller via this LoadBalancer service, and the controller will route the traffic to Kubernetes services as configured under Ingress Resources.

There are two Kubernetes objects in the ingress controller. There are two Kubernetes objects in the ingress controller.

a. (Optional) Although you may copy the information of the load balancer that was established as a service in the previous step or use the kubectl get services command to obtain the The load balancer’s specifications.

-o broad gives you a lot of information about a Kubernetes object (service)

The load balancer’s EXTERNAL-IP (afaf46………..us-east-1.elb.amazonaws.com) must be configured in the ingress resource file.

obtain services -o wide -w nginx-ingress-ingress-nginx-controller kubectl —namespace default

The load balancer's specifications The load balancer’s specifications

NGINX Application and Service Deployment

Using the Helm package manager, you previously installed an ingress controller. However, you’ll need a Kubernetes service operating in the Kubernetes cluster before you can use the ingress controller and ingress. Let’s start by creating a Kubernetes service using the instructions below.

Assuming you’re still using SSH to connect to your Kubernetes cluster:

1. Create a configuration file titled NGINX.yaml in the /nginx-ingress-controller directory.

The nginx.yaml file below will build the nginx-deployment and nginx-service Kubernetes services. This setup will produce a Kubernetes service that can be accessed from the outside through a load-balanced external ingress service.

The service will be hosted on top of two replica pods in this deployment.

—- # Kubernetes API version api definition # # # # # # # # # # # # # # # # # # # # # Determining the object’s type to create: Deployment # A name string, UID, and optional namespace all contribute to the object’s unique identification. metadata: # The deployment’s name is nginx-deployment. nginx-deployment is the name of the project. # Labels are key/value pairs that may be assigned to objects like pods. # Labels are used to define the distinguishing characteristics of things that are important to users. nginx-first-app app: nginx-first-app spec: # 2 replicas enable you to choose the number of pods required for deployment. replicas: There are two selectors: match and non-match. nginx-first-app nginx-first-app nginx-first-app nginx-first-app metadata: template ################################################################# spec: This property allows you to provide container information like the image (nginx) the name of the container (nginx-pod) spec: containers: – nginx-pod – nginx – nginx – nginx – nginx – nginx – nginx – 1st version serviceable: metadata: # The service’s name is nginx-service. nginx-service is the name of the service provided by nginx. ClusterIP ports: type: type: type: type: type: type: type: type: type: type: type – targetPort: 8080 – port: 80 app: nginx-first-app selection

2. To construct the deployment and service, use the kubectl apply command.

apply -f nginx.yaml kubectl

3. Finally, use the kubectl get service command to see whether the nginx-service is correctly setup. This nginx service will be accessible using a load balancer ingress service.

get service using kubectl nginx-service

Taking a look at the service that was set up in the previous part Taking a look at the service that was set up in the previous part

The Ingress resource is used to expose the NGINX service.

Now that you’ve set up the NGINX ingress controller and the Kubernetes services, you’ll need to construct an ingress resource with rules to route traffic from the ingress controller service (type load balanced) external IP to the Kubernetes services.

Let’s get started by creating an ingress resource file and applying the settings.

Assuming you’re still in the terminal, here’s what you should do:

1. Using your chosen editor, create a file called kubernetes-ingress.yaml. The kubernetes-ingress.yaml file includes the rules for routing traffic from an external IP to the ingress controller service (type load balanced).

apiVersion:: thetworking.k8s.io/v1 # Defining the Kubernetes API version Metadata for Ingress: nginx spec: kubernetes-ingress name: kubernetes-ingress annotations: kubernetes.io/ingress.class: nginx name: kubernetes-ingress rules: # External name of load balancer ingress service – host: “afaf46a16b1014f6989bcb22e531f555-149922304.us-east-1.elb.amazonaws.com” # http: Paths of the rules: – pathType: “/” as a prefix path backend: # Kubernetes Service to which the kubernetes service will be redirected: nginx-service (name) (port) (number) (name) (number) (number) (number) (num

2. Then, as shown below, use the kubectl apply command to create the ingress resource in the cluster. The kubernetes-ingress.yaml file, which you will deploy in the following step, will enable you to access the Kubernetes service from outside the cluster.

apply -f kubectl Kubernetes-ingress.yaml

The kubernetes-ingress resource was established to provide access to Kubernetes services from outside the cluster through an ingress controller service (type load balanced) external IP address, as shown below.

Putting together the Kubernetes ingress Putting together the Kubernetes ingress

3. Finally, open your preferred browser and go to the load balancers’ external IP address to see whether the nginx service is accessible from the outside.

As you can see in the screenshot below, the web page displays the Welcome to NGINX page, indicating that the ingress is correctly configured and operating.

Checking for entrance Checking for entrance

Conclusion

You learned how to install and configure the NGINX ingress controller in this article, which may let you easily access Kubernetes services through an external URL.

So, which Kubernetes services will you access outside using ingress in the Kubernetes cluster?

The “kubernetes nginx ingress controller” is a Kubernetes Ingress Controller that allows for easy setup of an NGINX Ingress. This can be used to configure your app’s routing rules and allow access to the app through the Kubernetes cluster.

Related Tags

  • nginx ingress controller helm chart
  • nginx ingress controller example
  • kubernetes nginx ingress example
  • install nginx ingress controller helm
  • nginx ingress controller github