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:
Open the IAM console
Click on "Roles" and then "Create role"
Select "AWS service" as the type of trusted entity
Select "Elastic Container Service" as the service that will use this role
Choose the "AmazonEKSClusterPolicy" policy, which gives the role the necessary permissions to create and manage an EKS cluster
Give the role a name, such as "eks-cluster-role"
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:
Open the VPC console
Click on "Create VPC"
Give the VPC a name and select the IP range, such as "10.0.0.0/16"
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:
Open the EKS console
Click on "Create cluster"
Give the cluster a name and select the VPC that you created for the worker nodes
Select the IAM role that you created for the cluster
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>
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:
Open the IAM console
Click on "Roles" and then "Create role"
Select "AWS service" as the type of trusted entity
Select "EC2" as the service that will use this role
Choose the "AmazonEKSWorkerNodePolicy" policy, which gives the role the necessary permissions to access the resources required by worker nodes
Give the role a name, such as "eks-worker-node-role"
Click on "Create role" to create the role.
Step 6: Creating a Node Group and Attaching it to the EKS Cluster
Open the EKS console
Click on your EKS cluster
Click on "Create node group"
Give the node group a name and select the VPC and subnets that you created for the worker nodes
Select the EC2 IAM role that you created for the worker nodes
Choose the instance type and number of instances that you want to run
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:
Open the EC2 console
Click on "Auto Scaling Groups"
Click on your node group's auto scaling group
Click on "Edit"
Choose the desired minimum and maximum number of instances
Click on "Save" to save the changes
Step 8: Deploying an Application to the EKS Cluster
Run the following command to create a deployment:
kubectl create deployment <deployment-name> --image=<container-image>
Run the following command to expose the deployment as a Kubernetes service:
kubectl expose deployment <deployment-name> --type=LoadBalancer --port=80
Run the following command to check the status of the deployment:
kubectl get pods
Run the following command to check the status of the service:
kubectl get services
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.
Top comments (0)