How to set up Nginx Ingress Controller on Kubernetes

Share

Kubernetes Ingress is an API object that exposes HTTP and HTTPS  routes from outside the cluster to services within the cluster.  An Ingress can be set up to load balance traffic, provide name-based virtual hosting, and provide Services with externally-reachable URLs. An ingress is not used for exposing arbitrary ports or protocols.

A load balancer is typically used by an ingress controller to fulfill ingress requests, but it may also set up your edge router or additional frontends to assist in handling traffic. The ingress controller doesn’t come by default in the Kubernetes cluster. We will use helm to deploy the Nginx Ingress controller.

Follow the below steps to deploy the ingress controller

  • First, we will install the helm.
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
  • Add Nginx ingress repository to helm
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
  • Update the dataset
helm repo update
  • Install the ingress controller
helm install ingress-nginx ingress-nginx/ingress-nginx

Nginx

Deploying an application with an Ingress controller in AWS EKS

  • First, we will deploy an Nginx web application with a deployment manifest file.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-webapp
  labels:
    app: frontend
spec:
  replicas: 1
  selector:
    matchLabels:
       app: frontend
  template:
    metadata:
       labels:
         app: frontend
    spec:
     containers:
      - name: nginx-webapp
        image: harshithk/webapp:latest
        ports:
          - containerPort: 80
  • Next, we will create a ClusterIP service manifest file and deploy it.

 


apiVersion: v1
kind: Service
metadata:
  name: nginx-webapp
spec:
  type: ClusterIP
  ports:
    - targetPort: 80
      port: 80
  selector:
    app: frontend
  • Now we create an Ingress resource manifest file with routing rules and deploy it.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
 name: minimal-ingress
spec:
  ingressClassName: nginx
  rules:
   - http:
      paths:
       - path: /
         pathType: Prefix
         backend:
            service:
              name: nginx-webapp
              port:
                number: 80

Nginx

  • Now use Load Balancer External-IP to access the application.

Please contact our technical consultants if you have anything related to cloud infrastructure to be discussed.

Leave a Reply

Your email address will not be published.

*