Are you exploring Kubernetes and looking to set up your first Amazon EKS cluster?
Here's a
straightforward guide to get you started with AWS Elastic Kubernetes Service (EKS). Whether
you're a beginner or looking for a quick reference, this post has got you covered!
Step 1: Create an EKS Management Host
Start by launching an Ubuntu EC2 instance (a t2.micro works perfectly) on AWS. Then, install
the required tools:
1- Install kubectl
#curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.30.6/2024-11-15/bin/
linux/amd64/kubectl
#chmod +x ./kubectl
#sudo mv ./kubectl /usr/local/bin
#kubectl version --short --client
2- Install AWS CLI (Latest Version):
#sudo apt update && sudo apt install unzip -y
#curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o
"awscliv2.zip"
#unzip awscliv2.zip
#sudo ./aws/install
#aws --version
3- Install eksctl:
#curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/
download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
#sudo mv /tmp/eksctl /usr/local/bin
#eksctl version
Step 2: Configure IAM Role for EKS Management Host
🔑To manage your EKS cluster, create an IAM role with the necessary permissions:
• IAM: Full Access
• VPC: Full Access
• EC2: Full Access
• CloudFormation: Full Access
• Administrator Access
Role Name: Demo-eks-role
🔑 Attach Role to EC2 Instance:
1. Navigate to EC2 Dashboard → Select your instance → Security → Modify IAM Role.
2. Attach the Demo-eks-role.
Step 3: Create a VPC for Your EKS Cluster
Go to the VPC Dashboard and create a new VPC for your cluster. Configure it based on your
requirements, such as CIDR block, subnets, and route tables.
Step 4: Create a Security Group for the Cluster
Set up a security group for your EKS cluster and configure inbound rules to allow the required
traffic (e.g., SSH, HTTP, HTTPS).
Step 5: Create an EKS Cluster
Use eksctl to create your EKS cluster. Here’s an example command for the us region (us-east-
1):
eksctl create cluster \
--name eks-cluster \
--region us-east-1 \
--nodegroup-name eks-nodegroup \
--node-type t3.medium \
--nodes-min 2 \
--nodes-max 2 \
--vpc-public-subnets subnet-0275a83eb493a97a8,subnet-0dd08dc8f4d5cd7b4 \
--vpc-security-group-ids sg-0fa6391a37249a7e6 \
--zones us-east-1a,us-east-1b,us-east-1c
Use eksctl to create your EKS cluster. Here’s an example command for the Mumbai region (ap-
south-1):
eksctl create cluster \
--name eks-cluster \
--region ap-south-1 \
--nodegroup-name eks-nodegroup \
--node-type t3.medium \
--nodes-min 2 \
--nodes-max 2 \
--vpc-public-subnets subnet-0275a83eb493a97a8,subnet-0dd08dc8f4d5cd7b4 \
--vpc-security-group-ids sg-0fa6391a37249a7e6 \
--zones ap-south-1a,ap-south-1b,ap-south-1c
NOTE: Cluster creation takes 5-10 minutes. Be patient! Once complete, verify the cluster by
running:
#kubectl get nodes
Congratulations! Your EKS cluster is now ready to use. Start deploying your
Kubernetes applications and enjoy the power of scalable container
orchestration!
Deploying a Login Page on EKS: Step-by-Step Walkthrough
In this guide, I demonstrate how I deployed a responsive HTML-based login page within an
Amazon EKS cluster. The deployment is crafted for scalability and accessibility, using Kubernetes
ConfigMap, Pod, and Service YAML configurations to ensure a seamless workflow.
This approach showcases best practices, leveraging Kubernetes capabilities to host and expose a
static web application through a Load Balancer for external access.
Step 1: HTML Content Stored in ConfigMap
The login page's HTML content is stored in a Kubernetes ConfigMap for centralized management.
This approach simplifies updates and decouples static content from the application logic.
Here’s the nginx-login-configmap.yaml:
apiVersion: v1
kind: ConfigMap
metadata:
name: login-page-configmap
data:
index.html: |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Page</title>
<style>
/* CSS styles for responsive design and visual appeal */
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
color: #333;
}
.login-container {
background: #fff;
padding: 40px;
border-radius: 10px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 400px;
}
/* Additional styling omitted for brevity */
</style>
</head>
<body>
<div class="login-container">
<h2>Login</h2>
<form>
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="Enter
your username" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password"
placeholder="Enter your password" required>
</div>
<button type="submit" class="login-button">Login</button>
</form>
<div class="login-footer">
<p>Don't have an account? <a href="#">Sign Up</a></p>
<p><a href="#">Forgot Password?</a></p>
</div>
</div>
</body>
</html>
Command to Apply ConfigMap:
kubectl apply -f nginx-login-configmap.yaml
Step 2: Deploy the Pod
The application is hosted on an Nginx web server, with the HTML file served from the ConfigMap
as a mounted volume. This ensures that any changes to the ConfigMap are reflected dynamically.
Here’s the nginx-login.yaml:
apiVersion: v1
kind: Pod
metadata:
name: nginx-login-pod
labels:
app: nginx-login
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
volumeMounts:
- name: login-page-volume
mountPath: /usr/share/nginx/html
volumes:
- name: login-page-volume
configMap:
name: login-page-configmap
Command to Deploy the Pod:
kubectl apply -f nginx-login.yaml
Step 3: Expose the Application via a Load Balancer
To make the application accessible outside the cluster, I used a Kubernetes Service of type
LoadBalancer.
Here’s the nginx-login-svc.yaml:
yaml
Copy code
apiVersion: v1
kind: Service
metadata:
name: nginx-login-service
spec:
selector:
app: nginx-login
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
Command to Expose the Pod:
kubectl apply -f nginx-login-svc.yaml
Step 4: Access the Application
Once the Service is created, retrieve the external IP address of the Load Balancer:
kubectl get svc nginx-login-service
Open the external IP in your browser, and you’ll see the professional and responsive login page
live!
Summary
• ConfigMap: Stores the HTML content for centralized, dynamic updates.
• Pod: Hosts the Nginx server, serving the login page via ConfigMap as a mounted volume.
• Service: Exposes the application using a Load Balancer for external access.
This setup demonstrates how Kubernetes can streamline static content hosting while maintaining
flexibility and scalability.
Outcome: A fully functional and responsive login page deployed on Amazon EKS, accessible via a
public endpoint.
✨ This deployment is a great example of leveraging Kubernetes best practices to deliver scalable
and professional-grade web applications.