How to Set Up an EKS Cluster with Managed Node Group and AWS Ingress Controller: A Step-by-Step Guide to create through eksctl
I will guide you through the process of setting up an Amazon Elastic Kubernetes Service (EKS) cluster with a Managed Node Group and AWS Ingress Controller. This will allow you to efficiently manage your containerized applications and handle incoming traffic effectively.
Prerequisites
Before we begin, make sure you have the following prerequisites in place:
- An AWS account with the necessary permissions to create EKS clusters and related resources.
- The AWS Command Line Interface (CLI) installed and configured with access to your AWS account.
- kubectl (Kubernetes command-line tool) installed and configured on your local machine.
- Basic knowledge of Kubernetes concepts.
Step 1: Create an EKS Cluster
1.1. Open your terminal and ensure that your AWS CLI is properly configured.
1.2. Use the AWS CLI to create an EKS cluster with the following command:
aws eks create-cluster --name <cluster-name> --version <Kubernetes-version> --role-arn <eks-service-role-ARN> --resources-vpc-config subnetIds=<subnet-IDs>,securityGroupIds=<security-group-IDs>
Replace the placeholders with your desired values. The <cluster-name> is the name of your EKS cluster, <Kubernetes-version> is the desired Kubernetes version, <eks-service-role-ARN> is the ARN of the IAM role for the EKS service, and <subnet-IDs> and <security-group-IDs> are the IDs of the subnets and security groups where your EKS nodes will reside.
1.3. Wait for the cluster to be created. This might take a few minutes.
Step 2: Create a Managed Node Group
2.1. To create a Managed Node Group, use the following AWS CLI command:
aws eks create-nodegroup --cluster-name <cluster-name> --nodegroup-name <nodegroup-name> --instance-types <instance-type> --subnet-ids <subnet-IDs> --ami-type <ami-type> --remote-access ec2SshKey=<EC2-key-pair>
Replace <nodegroup-name> with your preferred name for the node group, <instance-type> with the desired EC2 instance type for the nodes, <subnet-IDs> with the IDs of the subnets where the nodes will be deployed, <ami-type> with the AMI type (AL2_x86_64 or AL2_x86_64_GPU), and <EC2-key-pair> with the name of your EC2 key pair for SSH access.
2.2. Wait for the Managed Node Group to be created and for nodes to join the cluster.
Step 3: Deploy the AWS Ingress Controller
3.1. Deploy the AWS Load Balancer Controller, which is the AWS Ingress Controller for EKS clusters, using the following command:
kubectl apply -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller/crds?ref=release-1.2"
3.2. Next, add the AWS Helm repository and install the AWS Load Balancer Controller:
helm repo add eks https://aws.github.io/eks-charts
helm upgrade -i aws-load-balancer-controller eks/aws-load-balancer-controller -n kube-system --set clusterName=<cluster-name>
Ensure you replace <cluster-name>
with the name of your EKS cluster.
3.3. Wait for the controller to be deployed and ready.
kubectl cluster-info
kubectl get nodes
kubectl get nodegroups
kubectl get deployment -n kube-system alb-ingress-controller
Step 4: Create an Ingress Resource
Create an Ingress resource that defines how incoming traffic should be routed to your services. Here’s an example Ingress resource:
#alb-ingress.yaml
# Annotations Reference: https://kubernetes-sigs.github.io/aws-alb-ingress-controller/guide/ingress/annotation/
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
labels:
app:my-app-deployment
annotations:
# Ingress Core Settings
kubernetes.io/ingress.class: "alb"
alb.ingress.kubernetes.io/scheme: internet-facing
# Health Check Settings
alb.ingress.kubernetes.io/healthcheck-protocol: HTTP
alb.ingress.kubernetes.io/healthcheck-port: traffic-port
alb.ingress.kubernetes.io/healthcheck-path: /
alb.ingress.kubernetes.io/healthcheck-interval-seconds: '15'
alb.ingress.kubernetes.io/healthcheck-timeout-seconds: '5'
alb.ingress.kubernetes.io/success-codes: '200'
alb.ingress.kubernetes.io/healthy-threshold-count: '2'
alb.ingress.kubernetes.io/unhealthy-threshold-count: '2'
spec:
rules:
- http:
paths:
- path: /*
backend:
serviceName: api1
servicePort: 80
Apply the Ingress resource to your cluster with the following command:
kubectl apply -f alb-ingress.yaml
Step 5: Create a Deployment and Service
Create a Kubernetes Deployment manifest for your application:
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app-container
image: <your-app-image>
ports:
- containerPort: 80
Apply the Deployment manifest:
kubectl apply -f deployment.yaml
Create a Kubernetes Service manifest for your application:
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: my-app-deployment
labels:
app: my-app-deployment
spec:
type: NodePort
selector:
app: my-app-deployment
ports:
- port: 80
targetPort: 80
Apply the Service manifest:
kubectl apply -f service.yaml
Step 5: Verify the Setup
5.1. To ensure that everything is set up correctly, check the status of your EKS cluster, Managed Node Group, and Ingress Controller using the AWS CLI and kubectl.
5.2. Test the Ingress configuration by accessing your application through the AWS Application Load Balancer’s DNS name or IP address.
kubectl get deployments
kubectl describe deployment my-deployment
kubectl get services
kubectl describe service my-service
kubectl get ingress
kubectl describe ingress my-ingress
Congratulations! You have successfully set up an EKS cluster with a Managed Node Group and AWS Ingress Controller, allowing you to deploy and manage containerized applications efficiently.
Leave a Comment