Day 13: Introduction to Kubernetes on AWS with Amazon EKS
Welcome to Day 13 of our exciting "30 Days of AWS" journey! If you've been following along from the beginning, kudos to you for diving into the world of Amazon Web Services. Your dedication and curiosity are truly commendable.
For those who might have just joined us or are specifically interested in today's topic, a warm welcome to you as well! While each article in this series delves into a different facet of AWS, rest assured that they are all interconnected, building upon the knowledge we've been cultivating day by day.
If you're here for the first time, I encourage you to take a moment to catch up on our previous discussions. This will enhance your understanding and ensure a seamless flow as we dive deeper into the fascinating journey of AWS together.
In today’s installment, we will explore "Amazon EKS (Elastic Kubernetes Service)." Kubernetes is a very popular container orchestration tool, and EKS makes it easy to deploy, manage, and scale containerized applications using Kubernetes on AWS.
As always, feel free to engage, ask questions, and share your thoughts in the comments. Your participation is what makes this series vibrant and valuable. I’m thrilled to have you join us on this journey. Let’s get started!
What is Kubernetes?
Before we jump into Amazon EKS, let’s understand Kubernetes. If you think of Docker as a tool that packs up a single application into a neat container, Kubernetes is the entire delivery network that manages and orchestrates multiple containers.
Key Concepts of Kubernetes (Simplified)
Cluster:
A group of machines (physical or virtual) where all your containers run. It’s like a big factory with many workers (nodes) working together.Node:
An individual machine inside the cluster. Each node is responsible for running a set of containers.Pod:
A wrapper around one or more containers. Pods are the smallest unit of deployment in Kubernetes, and each pod has its own IP address and storage.Deployment:
Manages how many replicas (copies) of a pod should be running. For example, if you need 3 copies of a web server running, a deployment will ensure that exactly 3 pods are always active.Service:
Exposes your application (pods) to the outside world so users can access it. Think of it as a doorway to your application.
Why Use Kubernetes?
Automated Scaling:
Kubernetes can automatically increase or decrease the number of pods based on the application’s traffic and performance.Self-Healing:
If a pod crashes or becomes unhealthy, Kubernetes will replace it automatically without any manual intervention.Load Balancing:
Distributes incoming traffic evenly across all available pods, ensuring that no single pod gets overwhelmed.
What is Amazon EKS?
Now that we know the basics of Kubernetes, let’s talk about Amazon EKS (Elastic Kubernetes Service). EKS is a managed Kubernetes service provided by AWS. It simplifies running Kubernetes on AWS by handling the heavy lifting, like setting up the control plane (the "brain" of Kubernetes) and integrating with other AWS services.
Why Use EKS Instead of ECS?
Kubernetes Flexibility:
If you already use Kubernetes in your organization or prefer Kubernetes for its flexibility and community support, EKS is a natural choice.Complex Applications:
For applications that require multiple interconnected services, complex networking, or specific Kubernetes features, EKS is a better fit.Hybrid Cloud:
If you’re running Kubernetes on-premises or in other clouds, EKS allows you to maintain a consistent experience across environments.
Setting Up Your First EKS Cluster
Setting up an EKS cluster might seem a bit more complex compared to ECS, but don’t worry—we’ll walk through each step in detail.
Step 1: Create an EKS Cluster
Go to the EKS Console.
Click Create Cluster.
Provide a Cluster Name (e.g.,
my-first-eks-cluster
).Choose the Kubernetes Version (select the latest stable version).
Configure the Cluster Service Role (you might need to create a new role if it’s your first time).
Click Next and then Create.
EKS will take a few minutes to create the cluster. While it’s setting up, let’s move on to the next step.
Step 2: Launch EC2 Instances as Worker Nodes
EKS requires EC2 instances to run the actual containers (these are called worker nodes).
Go to the EC2 Console and click Launch Instance.
Choose an Amazon Linux 2 AMI (with EKS support).
Set the Instance Type to
t3.medium
or larger.Make sure you attach the EC2 instance to the same VPC and subnets as your EKS cluster.
Add the EC2 instance to the EKS Cluster Security Group.
Launch the instance, and note down the EC2 Instance ID.
Step 3: Connect EC2 Worker Nodes to EKS
Open the IAM Console.
Go to the Roles section and attach the
AmazonEKSWorkerNodePolicy
to the EC2 instance.Go back to the EKS Console and click on your cluster.
Click Compute and then Add Node Group.
Name your node group (e.g.,
worker-nodes
) and select the EC2 instance ID you created earlier.
This will connect your EC2 instances to the EKS cluster.
Step 4: Deploy a Sample Application on EKS
Let’s deploy a simple web server using Kubernetes commands:
Open your Cloud9 IDE or your local terminal with
kubectl
installed.Create a YAML file named
nginx-deployment.yaml
:apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80
Apply the YAML file to your cluster:
kubectl apply -f nginx-deployment.yaml
Verify that the pods are running:
kubectl get pods
Step 5: Expose the Application
Expose the deployment so that users can access it:
kubectl expose deployment nginx-deployment --type=LoadBalancer --port=80
This command creates a load balancer that routes traffic to your nginx
pods. You can access the application using the Load Balancer URL displayed in the terminal.
Summary
Today, we explored:
What Kubernetes is and why it’s a powerful container orchestration tool.
How Amazon EKS simplifies running Kubernetes on AWS.
Setting up an EKS cluster, connecting worker nodes, and deploying a sample application.
What’s Next?
In Day 14, we’ll explore how to integrate EKS with other AWS services, such as monitoring with CloudWatch, managing secrets with Secrets Manager, and automating deployments.
Stay tuned, and let’s keep this AWS learning journey going strong!
Hope you find this blog helpful. Please share your thoughts in the comments—it will help me refine and provide more insightful content. Happy Learning!
Connect with Me - LinkedIn - Twitter/X - Topmate