DEV Community

Cover image for Create an EKS cluster with the AWS Management Console
Vrashabh Sontakke
Vrashabh Sontakke

Posted on

Create an EKS cluster with the AWS Management Console

Creating an Amazon Elastic Container Service for Kubernetes (EKS) Cluster

Kubernetes is an open-source platform for managing and deploying containers. With Amazon Elastic Container Service for Kubernetes (EKS), you can easily manage and deploy your containerized applications on the AWS cloud. In this blog, we'll go through the steps to create an EKS cluster and deploy an application.

Step 1: Creating an IAM Role

Before creating an EKS cluster, you need to create an IAM role that will allow EKS to manage the resources required for your cluster. To create an IAM role, follow these steps:

  1. Open the IAM console
  2. Click on "Roles" and then "Create role"
  3. Select "AWS service" as the type of trusted entity
  4. Select "Elastic Container Service" as the service that will use this role
  5. Choose the "AmazonEKSClusterPolicy" policy, which gives the role the necessary permissions to create and manage an EKS cluster
  6. Give the role a name, such as "eks-cluster-role"
  7. Click on "Create role" to create the role

Step 2: Creating a VPC for Worker Nodes

Next, you need to create a VPC for the worker nodes in your EKS cluster. Follow these steps:

  1. Open the VPC console
  2. Click on "Create VPC"
  3. Give the VPC a name and select the IP range, such as "10.0.0.0/16"
  4. Click on "Create" to create the VPC

Step 3: Creating an EKS Cluster for Master Nodes

To create an EKS cluster, you need to create a master node and then connect the worker nodes to the master node. Follow these steps:

  1. Open the EKS console
  2. Click on "Create cluster"
  3. Give the cluster a name and select the VPC that you created for the worker nodes
  4. Select the IAM role that you created for the cluster
  5. Click on "Create" to create the EKS cluster

Step 4: Connecting to kubectl with EKS

Once you have created your EKS cluster, you can connect to it using kubectl, the Kubernetes command-line tool. To do this, you need to install kubectl and then configure it to connect to your EKS cluster.

Install kubectl by following the instructions on the Kubernetes website
Run the following command to configure kubectl to connect to your EKS cluster:

aws eks update-kubeconfig --name <cluster-name>
Enter fullscreen mode Exit fullscreen mode

Step 5: Creating an EC2 IAM Role for Node Group

Next, you need to create an EC2 IAM role that will allow your worker nodes to access the resources they need. To create an EC2 IAM role, follow these steps:

  1. Open the IAM console
  2. Click on "Roles" and then "Create role"
  3. Select "AWS service" as the type of trusted entity
  4. Select "EC2" as the service that will use this role
  5. Choose the "AmazonEKSWorkerNodePolicy" policy, which gives the role the necessary permissions to access the resources required by worker nodes
  6. Give the role a name, such as "eks-worker-node-role"
  7. Click on "Create role" to create the role.

Step 6: Creating a Node Group and Attaching it to the EKS Cluster

With the EC2 IAM role in place, you can now create a node group and attach it to your EKS cluster. A node group is a group of EC2 instances that run the Kubernetes worker nodes. To create a node group, follow these steps:

  1. Open the EKS console
  2. Click on your EKS cluster
  3. Click on "Create node group"
  4. Give the node group a name and select the VPC and subnets that you created for the worker nodes
  5. Select the EC2 IAM role that you created for the worker nodes
  6. Choose the instance type and number of instances that you want to run
  7. Click on "Create" to create the node group and attach it to the EKS cluster

Step 7: Configuring Autoscaling

By default, your node group will have a fixed number of instances, but you can configure autoscaling so that the number of instances increases or decreases based on demand. To configure autoscaling, follow these steps:

  1. Open the EC2 console
  2. Click on "Auto Scaling Groups"
  3. Click on your node group's auto scaling group
  4. Click on "Edit"
  5. Choose the desired minimum and maximum number of instances
  6. Click on "Save" to save the changes

Step 8: Deploying an Application to the EKS Cluster

With your EKS cluster and node group in place, you can now deploy an application to the cluster. To deploy an application, you need to create a Kubernetes deployment that specifies the application's container image and other parameters. To create a deployment, follow these steps:

Run the following command to create a deployment:

kubectl create deployment <deployment-name> --image=<container-image>
Enter fullscreen mode Exit fullscreen mode

Run the following command to expose the deployment as a Kubernetes service:

kubectl expose deployment <deployment-name> --type=LoadBalancer --port=80
Enter fullscreen mode Exit fullscreen mode

Run the following command to check the status of the deployment:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Run the following command to check the status of the service:

kubectl get services
Enter fullscreen mode Exit fullscreen mode

Your application should now be running in your EKS cluster and accessible through the Kubernetes service.

In conclusion, creating an EKS cluster is a straightforward process that requires creating an IAM role, creating a VPC for the worker nodes, creating an EKS cluster for the master nodes, connecting to kubectl with EKS, creating an EC2 IAM role for the node group, creating a node group and attaching it to the EKS cluster, configuring autoscaling, and deploying an application to the EKS cluster. With these steps, you can easily create and manage a scalable, highly available Kubernetes environment on the AWS cloud.

Oldest comments (0)