hapleafacademy avatar

Share with

,

Set Up Kubernetes on AWS – Step by Step Guide

Set up Kubernetes on AWS

Do you want to set up Kubernetes on AWS? You have landed at the right place!

Kubernetes is a powerful container orchestration platform that allows you to automate the deployment, scaling, and management of containerized applications. This guide will walk you through the Kubernetes cluster setup on AWS (Amazon Web Services) using Amazon Elastic Kubernetes Service (EKS).

Prerequisites:

  • An AWS account with administrative privileges
  • Basic understanding of AWS services like IAM and VPCs
  • AWS CLI (Command Line Interface) installed and configured

Set Up Kubernetes on AWS – Step by Step Details

Step 1: Create an IAM Role for EKS

EKS requires an IAM role with specific permissions to manage Kubernetes resources within your cluster.

  1. Go to the IAM service in the AWS Management Console.
  2. Click on “Roles” in the left navigation pane.
  3. Click on “Create role”.
  4. Under “AWS service”, select “Amazon EKS”.
  5. Choose “AmazonEKSClusterRole” as the use case.
  6. Click on “Next: Permissions”.
  7. Search for the policy named “AmazonEKSClusterPolicy” and select the checkbox next to it.
  8. Click on “Review” and then “Create role”.
  9. Make note of the role name you created, as you’ll need it later.

Step 2: Create a Virtual Private Cloud (VPC)

A VPC provides a logically isolated network for your cluster resources.

  1. Go to the VPC service in the AWS Management Console.
  2. Click on “VPCs” in the left navigation pane.
  3. Click on “Create VPC”.
  4. Choose a name for your VPC (e.g., eks-vpc).
  5. AWS automatically creates a default /16 CIDR block for your VPC. You can leave this as is for most basic setups.
  6. Click on “Create”.

Step 3: Create Subnets

Subnets define smaller sections within your VPC where you’ll launch your cluster resources.

  1. Go to the VPC service in the AWS Management Console and select your VPC (e.g., eks-vpc)
  2. Click on “Subnets” in the left navigation pane.
  3. Click on “Create subnet”.
  4. Choose a name for your subnet (e.g., eks-public-subnet).
  5. Select the Availability Zone where you want to launch the subnet (choose at least two for redundancy).
  6. From the CIDR block dropdown, select an unused CIDR block within your VPC’s overall CIDR range (e.g., 10.0.0.0/16). You can choose a smaller block size like /24 for your subnet.
  7. Under “Auto-assign Public IP”, choose “Yes”. This allows your worker nodes to communicate with the internet if needed.
  8. Click on “Create subnet”.
  9. Repeat steps 3-8 to create one or more additional subnets in different Availability Zones for redundancy. These can be private subnets without public IP assignment if your worker nodes don’t require internet access.

Step 4: Create an Internet Gateway (Optional)

An internet gateway allows your cluster resources to access the internet if needed. This step is optional depending on your application requirements.

  1. Go to the VPC service in the AWS Management Console and select your VPC (e.g., eks-vpc).
  2. Click on “Internet Gateways” in the left navigation pane.
  3. Click on “Create internet gateway”.
  4. Choose a name for your internet gateway (e.g., eks-internet-gateway).
  5. Click on “Create internet gateway”.

Step 5: Create a Route Table

A route table determines how traffic is routed within your VPC.

  1. Go to the VPC service in the AWS Management Console and select your VPC (e.g., eks-vpc).
  2. Click on “Route tables” in the left navigation pane.
  3. Click on “Create route table”.
  4. Choose a name for your route table (e.g., eks-public-route-table).
  5. Click on “Create”.
  6. Select your newly created route table.
  7. Click on “Routes” in the left navigation pane.
  8. Click on “Edit routes”.
  9. In the “Destination” field, enter “0.0.0.0/0” (represents all traffic).
  10. In the “Target” field, select “Internet Gateway”.
  11. From the dropdown menu, select the internet gateway you created earlier (e.g., eks-internet-gateway).
  12. Click on “Update”.

Step 6: Associate Subnet(s) with the Route Table

  1. Go to the VPC service in the AWS Management Console and select your VPC (e.g., eks-vpc).
  2. Click on “Subnets” in the left navigation pane.
  3. Select the public subnet you created earlier (e.g., eks-public-subnet).
  4. Under “Subnet Actions”, click on “Edit subnet associations”.
  5. From the “Route table association” dropdown menu, select the route table you created (e.g., eks-public-route-table).
  6. Click on “Update subnet associations”.

Step 7: Launch a Cluster using eksctl (Optional)

eksctl is a popular open-source command-line tool for managing EKS clusters. While the AWS Management Console offers a visual interface for cluster creation, eksctl provides more flexibility and automation options.

Installing eksctl (if using):

Follow the official eksctl installation instructions based on your operating system: https://docs.aws.amazon.com/eks/latest/userguide/setting-up.html

Cluster creation using eksctl (example command):

eksctl create cluster \
  --name my-eks-cluster \
  --version 1.24 \
  --region us-east-1 \
  --vpc <VPC_ID> \
  --node-group-name standard-workers \
  --nodes 2 \
  --node-type t3.medium \
  --with-addNodePolicy=AutoScaling \
  --asg-min-size 2 \
  --asg-max-size 4 \
  --sshPublicKey <PATH_TO_YOUR_PUBLIC_KEY>

Replace the placeholders with your specific values:

  • <VPC_ID>: The ID of your VPC created in Step 2.
  • <PATH_TO_YOUR_PUBLIC_KEY>: The path to your SSH public key file for worker node access.

Step 8: Verify Cluster Access (using kubectl)

Obtaining kubeconfig:

  • Using AWS Management Console: After cluster creation, download the kubeconfig file from the EKS cluster details page.
  • Using eksctl: The eksctl create cluster command (from Step 7) automatically downloads and configures kubectl for your cluster.

Verifying cluster access:

kubectl get nodes

This command should list the worker nodes in your EKS cluster, indicating successful cluster access.

Congratulations! You’ve successfully set up a basic Kubernetes cluster on AWS using Amazon EKS.

Additional Considerations for set up of Kubernetes on AWS

  • Security Groups: Configure security groups for your cluster resources to control inbound and outbound traffic.
  • IAM Roles for Worker Nodes: Create an IAM role with specific permissions for your worker nodes to access AWS resources on your behalf.
  • Cluster Scaling: EKS allows automatic scaling of worker nodes based on your needs. Explore options for auto scaling groups within the EKS console or eksctl commands.
  • Networking Configuration: You can configure advanced networking options within your cluster using Kubernetes concepts like pods, services, and network policies.

By following these steps and considering the additional points, you can establish a secure and scalable Kubernetes cluster on AWS to deploy and manage your containerized applications.

Let us know your experience of working with Kubernetes on AWS.


Recommended books on Software Programming:

Stay updated with the latest posts by following the HapleafAcademy WhatsApp Channel
hapleafacademy avatar
Index