Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 61

Deploying EKS with eksctl and Kubectl Configuration

This lesson is built with resources from youtube.com, blog.kemanedonfack.com and 1 more site.

Hello! Welcome to Module 10 of our course.

In the last module, you mastered containerizing our Spring Boot microservices with Docker and running the entire stack locally using Docker Compose. Crucially, you learned how to debug running containers using docker logs and docker exec, skills that are fundamental to modern software development.

Now, we're ready to move from local development to a cloud environment. While Docker Compose is excellent for local setups, it's not designed to manage applications in a production setting across multiple servers. For that, we need a container orchestrator.

This lesson marks our first step into Kubernetes, the industry-standard for container orchestration. We will provision our first production-style Kubernetes cluster on Amazon Web Services (AWS). You will learn about Amazon EKS (Elastic Kubernetes Service), a managed service that simplifies running Kubernetes, and use eksctl, a powerful command-line tool, to get our cluster up and running.

MERN Stack Comparison

In the MERN world, you might deploy a smaller application to a Platform-as-a-Service (PaaS) like Heroku or Vercel, or use a process manager like PM2 on a single virtual machine. For large-scale, distributed systems, Kubernetes is the de facto standard, regardless of the programming language. Think of it as the operating system for a data center. Learning Kubernetes is a critical step in becoming a platform engineer, and the concepts are universal across tech stacks.



1. From Docker Compose to Kubernetes

So far, we've defined our services, networks, and dependencies in a docker-compose.yml file. This works perfectly on a single machine. But what happens in production when you need to:

  • Run services across multiple servers for high availability?
  • Automatically restart a service if it crashes?
  • Scale a service up or down based on traffic?
  • Perform updates with zero downtime?

This is where a container orchestrator like Kubernetes comes in. It automates the deployment, scaling, and management of containerized applications.

Amazon EKS (Elastic Kubernetes Service) is AWS's managed Kubernetes offering. It handles the difficult parts of running Kubernetes for you, specifically the "control plane" (the brain of the cluster), so you can focus on deploying your applications.

This sounds complex, and setting up all the required AWS components (networking, permissions, servers) manually can be. To simplify this, we will use eksctl, a command-line tool by Weaveworks that automates the entire process.

AWS EKS - Create Kubernetes cluster on Amazon EKS | the easy way

To understand the problem EKS and eksctl solve, watch this introduction from the "AWS EKS" video by TechWorld with Nana. It provides a high-level overview of the manual steps required to create a cluster and contrasts them with the simplicity of using eksctl.

Watch the segment from the beginning until 07:22. Pay attention to the distinction between the managed control plane (AWS's responsibility) and the worker nodes (our responsibility), and how eksctl automates the setup of both.

Behind the scenes, eksctl uses AWS CloudFormation to create a "stack" of resources. This is a form of Infrastructure as Code (IaC), where you define your infrastructure declaratively.

EKS Cluster Deployment Architecture with eksctl
This diagram illustrates how `eksctl` uses AWS CloudFormation to provision all the necessary infrastructure for an EKS cluster. This includes the VPC, subnets across multiple availability zones for high availability, and the EKS nodes (EC2 instances) that will run our application pods.


2. Prerequisites and Local Setup

Before we can create a cluster, we need to set up our local machine with the necessary tools and credentials.

You will need:

  1. An AWS Account: Ensure you have an AWS account with administrative privileges. Creating an EKS cluster will incur costs, so be prepared for that and remember to clean up resources at the end.
  2. AWS CLI: The command-line interface for interacting with AWS.
  3. kubectl: The command-line tool for interacting with any Kubernetes cluster.
  4. eksctl: The CLI for creating and managing EKS clusters.

Step 1: Install kubectl and eksctl

If you are on a Mac, you can use Homebrew. For other operating systems, please refer to the official documentation.




# Install kubectl
brew install kubectl




# Install eksctl
brew install weaveworks/tap/eksctl

You can verify the installations by running kubectl version --client and eksctl version.

Step 2: Configure AWS Credentials

eksctl needs credentials to create resources in your AWS account. It uses the same configuration as the AWS CLI. The best practice is to create an IAM user with programmatic access and configure your local machine with its access key and secret key.

AWS EKS Tutorial | What is EKS? | EKS Explained | KodeKloud

The video "AWS EKS Tutorial" by KodeKloud provides a clear, step-by-step guide on creating an access key in the AWS IAM console and configuring it locally.

Watch from 11:01 to 13:42. Follow the instructions to create an access key for your IAM user and then configure your local environment using either aws configure or by manually creating the ~/.aws/credentials and ~/.aws/config files.

After this step, you should have your AWS credentials configured, allowing eksctl to act on your behalf.



3. Hands-On: Provisioning Your First EKS Cluster (35-40 minutes)

Now for the main event. We will use a single eksctl command to provision a complete EKS cluster.

A quick note on cost and instance types: The worker nodes in your cluster are EC2 instances, and you pay for them as long as they are running. We'll use the t3.medium instance type, which provides a good balance of CPU and memory for running our full application stack later.

Step 1: Run the eksctl Create Command

Open your terminal and run the following command. Be patient, as this process typically takes 15-20 minutes.

eksctl create cluster \
--name blog-platform-cluster \
--region us-east-1 \
--nodegroup-name standard-workers \
--node-type t3.medium \
--nodes 2 \
--nodes-min 2 \
--nodes-max 3

Let's break down this command:

  • --name blog-platform-cluster: Gives your EKS cluster a unique name.
  • --region us-east-1: Specifies the AWS region to create the cluster in. Feel free to choose a region closer to you.
  • --nodegroup-name standard-workers: A name for the group of EC2 instances that will be your worker nodes.
  • --node-type t3.medium: The EC2 instance size for the worker nodes.
  • --nodes 2: The initial number of worker nodes to create.
  • --nodes-min 2 and --nodes-max 3: Configures the autoscaling group for your nodes. This allows the cluster to automatically add a node (up to 3) if resources are scarce.

While the command runs, it will print out the numerous steps it's performing, such as setting up the VPC and creating the EKS control plane.

Step 2: Verify the Cluster Connection

Once the creation command completes successfully, eksctl does something magical: it automatically updates your local kubectl configuration file (~/.kube/config) with the new cluster's details and credentials.

Now, you can verify that kubectl can communicate with your new remote cluster.

AWS EKS - Create Kubernetes cluster on Amazon EKS | the easy way

This clip from TechWorld with Nana demonstrates exactly what to do after the cluster is created.

Watch from 13:37 to 14:42. You'll see how eksctl saves the kubeconfig and how to use kubectl get nodes to confirm the connection.

Run the following command in your terminal:

kubectl get nodes

If everything worked, you should see an output listing your two worker nodes with a Ready status.

NAME                                           STATUS   ROLES    AGE   VERSION
ip-192-168-XX-XX.us-east-1.compute.internal    Ready    <none>   5m    v1.28.3-eks-036c24b
ip-192-168-XX-XX.us-east-1.compute.internal    Ready    <none>   5m    v1.28.3-eks-036c24b

Congratulations! You have a fully functional Kubernetes cluster running in AWS, and your local machine is configured to manage it.



4. Debugging and Cleanup

Debugging First: What if the eksctl create cluster command fails? The terminal output will usually contain the error. For more detail, you can navigate to the AWS CloudFormation service in the AWS Console. Find the stack named eksctl-blog-platform-cluster-cluster and look at the "Events" tab. This log will show every step eksctl attempted and where it failed, which is invaluable for troubleshooting.

Cost Management: Your EKS cluster incurs costs as long as it exists. It is critical to delete it when you are not using it.

To tear down the cluster and all associated resources (EC2 instances, VPC, etc.), run this command:

eksctl delete cluster --name blog-platform-cluster --region us-east-1

This process will also take about 10-15 minutes. Always double-check in the AWS console (under EC2 -> Instances and EKS -> Clusters) to ensure all resources have been terminated.



Conclusion

In this lesson, you made the significant leap from local containerization to cloud orchestration. You learned the "why" behind Kubernetes and EKS and used eksctl to abstract away immense complexity, provisioning a production-ready cluster with a single command.

Key Takeaways:

  • Kubernetes orchestrates containers at scale, solving problems like high availability, self-healing, and scaling that Docker Compose doesn't address.
  • Amazon EKS is a managed service that runs the Kubernetes control plane for you.
  • eksctl is a powerful CLI that automates the creation and management of EKS clusters and their underlying AWS resources.
  • The eksctl create cluster command provisions a cluster and automatically configures your local kubectl.
  • The kubectl get nodes command is the fundamental check to verify connectivity to your cluster.
  • Always remember to delete your cluster with eksctl delete cluster to avoid unnecessary AWS costs.

Preview of the Next Lesson:
Our cluster is currently empty. In the next lesson, we will start deploying our application to it. You will learn how to write Kubernetes manifest files (.yaml) to define a Deployment, which describes how to run our Spring Boot services, and a Service, which describes how to expose them for communication within the cluster.