How to create an Nginx ingress controller with aws classic load balancer in 2023

You are currently viewing How to create an Nginx ingress controller with aws classic load balancer in 2023

This article will discuss how to create an Nginx Ingress controller with an AWS Classic Load Balancer. An Nginx Ingress controller is a way to route external traffic to multiple services within a Kubernetes cluster. An AWS Classic Load Balancer, on the other hand, is a type of load balancer that is used to distribute incoming traffic across multiple instances in the AWS ecosystem. Together, these two tools can create a highly available and scalable infrastructure for your applications.

To create an NGINX ingress controller with an AWS Classic Load Balancer (CLB) on an EKS cluster, you can follow these steps:

1. At first, we need to create a cluster in EKS by running the below command. For creating the cluster I will use eksctl. Here is the command

curl --silent --location "$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin

create cluster.yml file with the following data. ( change it based on your needs )

kind: ClusterConfig

  name: atiqur-cluster
  region: us-east-1

  - name: ng-spot-1
    instanceType: mixed
      instanceTypes: ["t3.large"] # List of instance types
      maxPrice: 0.05 # Maximum price for spot instances, in USD
      onDemandBaseCapacity: 0
      spotInstancePools: 2 # Number of spot instance pools
    minSize: 1
    maxSize: 4
    desiredCapacity: 2
    volumeSize: 20

Then run this command to create the cluster

eksctl create cluster -f cluster.yml

The EKS cluster creation will take around 5-10 mins. Once the cluster is created then copy the cluster name and run the following command to update the “kubectl” with cluster information

aws eks update-kubeconfig --region {aws-region-name} --name {eks-cluster-name}

Before you run, replace the region-name and cluster-name parameters with your current region and cluster name.

Create a service account and role binding for the ingress controller. This will allow the ingress controller to interact with the Kubernetes API server.

kubectl create serviceaccount nginx-ingress-controller
kubectl create clusterrolebinding nginx-ingress-controller --clusterrole=cluster-admin --serviceaccount=default:nginx-ingress-controller

2. Create a namespace for the ingress controller

kubectl create namespace ingress-nginx

3. Use Helm to install the ingress controller

First, install Helm. The instructions to install Helm on AWS are given here.

Then add the repo of the nginx ingress controller.

helm repo add ingress-nginx 
helm repo update

Then install the Nginx-ingress controller with Classic load balancer.

helm install nginx-ingress ingress-nginx/ingress-nginx --namespace ingress-nginx --set controller.service.annotations."service\.beta\.kubernetes\.io/aws-load-balancer-type"=classic

Alternatively, you can install a Network Load balancer.

helm install nginx-ingress ingress-nginx/ingress-nginx --namespace ingress-nginx --set controller.service.annotations."service\.beta\.kubernetes\.io/aws-load-balancer-type"=nlb

4. Verify that the ingress controller is running by using the “kubectl get pods -n ingress-nginx” command and checking for pods with the name nginx-ingress-controller-*.

5 Here is one sample deployment file that will create one service and link it with the Nginx ingress in a path.

apiVersion: apps/v1
kind: Deployment
  name: test-app
    app: test-app
  replicas: 3
      app: test-app
        app: test-app
      - name: test-app
        image: nginx:latest
        - containerPort: 80
            cpu: 100m
            memory: 128Mi
            cpu: 50m
            memory: 64Mi
apiVersion: v1
kind: Service
  name: atiq-service  
  type: NodePort
  - port: 80
    app: test-app
kind: Ingress
  name: test-app-ingress
  annotations: "false" 'nginx' "true" /$2
  - http:
      - path: /atiq(/|$)(.*)
        pathType: Prefix
            name: atiq-service
              number: 80


Following the steps outlined in this article, you should now have a working Nginx Ingress controller and AWS Classic Load Balancer set up for your Kubernetes cluster. This setup will allow you to easily route external traffic to multiple services within your cluster, while also providing high availability and scalability for your applications. However, it’s worth noting that this is just one way to set up a load balancer, and different situations may call for different solutions. But the concept, the process, and the tools are the same and can be used in other setups as well.

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply