DEV Community

akhil mittal
akhil mittal

Posted on

Deploying Applications in Amazon EKS with NGINX Ingress

Here’s a step-by-step guide to deploying your application in Amazon EKS and exposing it using the NGINX Ingress Controller:

Step 1: Set Up NGINX Ingress Controller in EKS

  1. Install NGINX Ingress Controller using Helm: Ensure that Helm is installed and configured with your EKS cluster. Add the NGINX Ingress repository and install the NGINX Ingress Controller:
   helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
   helm repo update
   helm install nginx-ingress ingress-nginx/ingress-nginx --namespace ingress-nginx --create-namespace
Enter fullscreen mode Exit fullscreen mode

This command deploys the NGINX Ingress Controller with a LoadBalancer service type, making it accessible outside the EKS cluster.

  1. Verify the Installation: Confirm that the NGINX Ingress Controller is running and accessible:
   kubectl get pods -n ingress-nginx
   kubectl get svc -n ingress-nginx
Enter fullscreen mode Exit fullscreen mode

Note the external IP assigned to the nginx-ingress-controller service. This IP will be used to access your applications.

Step 2: Deploy Your Application in EKS

  1. Create a Deployment: Write a YAML file (e.g., myapp-deployment.yaml) to define your application deployment in Kubernetes. Here’s a basic example:
   apiVersion: apps/v1
   kind: Deployment
   metadata:
     name: myapp
     namespace: default
   spec:
     replicas: 2
     selector:
       matchLabels:
         app: myapp
     template:
       metadata:
         labels:
           app: myapp
       spec:
         containers:
         - name: myapp-container
           image: your-docker-image:latest
           ports:
           - containerPort: 80
Enter fullscreen mode Exit fullscreen mode

Apply this deployment:

   kubectl apply -f myapp-deployment.yaml
Enter fullscreen mode Exit fullscreen mode
  1. Create a Service for Your Application: To expose your application within the cluster, create a ClusterIP service (e.g., myapp-service.yaml):
   apiVersion: v1
   kind: Service
   metadata:
     name: myapp-service
     namespace: default
   spec:
     selector:
       app: myapp
     ports:
     - protocol: TCP
       port: 80
       targetPort: 80
     type: ClusterIP
Enter fullscreen mode Exit fullscreen mode

Apply this service:

   kubectl apply -f myapp-service.yaml
Enter fullscreen mode Exit fullscreen mode

Step 3: Configure Ingress for External Access

  1. Create an Ingress Resource: The Ingress resource defines how external traffic will reach your application through the NGINX Ingress Controller. Create an Ingress YAML file (e.g., myapp-ingress.yaml):
   apiVersion: networking.k8s.io/v1
   kind: Ingress
   metadata:
     name: myapp-ingress
     namespace: default
     annotations:
       nginx.ingress.kubernetes.io/rewrite-target: /
   spec:
     rules:
     - host: your-domain.com
       http:
         paths:
         - path: /
           pathType: Prefix
           backend:
             service:
               name: myapp-service
               port:
                 number: 80
Enter fullscreen mode Exit fullscreen mode

Replace your-domain.com with your actual domain. If you don’t have a domain, you can use the external IP address of the NGINX Ingress Controller for testing.

Apply this Ingress resource:

   kubectl apply -f myapp-ingress.yaml
Enter fullscreen mode Exit fullscreen mode
  1. Update DNS (Optional): If you’re using a domain, create a DNS A record pointing to the external IP of the NGINX Ingress Controller. This allows you to access your application at http://your-domain.com.

Step 4: Access the Application

  1. Test the Setup:
    Open a browser and navigate to http://your-domain.com. You should see your application’s web page, confirming that the NGINX Ingress Controller is routing traffic correctly to your application.

  2. Verify Ingress Logs (Optional):
    If you encounter issues, check the logs of the Ingress Controller to troubleshoot:

   kubectl logs -n ingress-nginx -l app.kubernetes.io/name=ingress-nginx
Enter fullscreen mode Exit fullscreen mode

Summary

  • Deploy NGINX Ingress Controller to expose services externally.
  • Deploy your application as a Deployment and expose it via a ClusterIP Service.
  • Create an Ingress resource to route external traffic to your application through the NGINX Ingress Controller.

This setup provides a flexible way to manage and expose applications in Kubernetes, especially in production-grade environments.

Top comments (0)