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
- 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
This command deploys the NGINX Ingress Controller with a LoadBalancer
service type, making it accessible outside the EKS cluster.
- 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
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
-
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
Apply this deployment:
kubectl apply -f myapp-deployment.yaml
-
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
Apply this service:
kubectl apply -f myapp-service.yaml
Step 3: Configure Ingress for External Access
-
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
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
-
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 athttp://your-domain.com
.
Step 4: Access the Application
Test the Setup:
Open a browser and navigate tohttp://your-domain.com
. You should see your application’s web page, confirming that the NGINX Ingress Controller is routing traffic correctly to your application.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
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.