Kubernetes Cluster on AWS EKS

Setting Up Your First Kubernetes Cluster on AWS EKS

In the era of cloud-native applications, Kubernetes has emerged as the go-to orchestration tool for managing containerized applications. AWS EKS (Elastic Kubernetes Service) makes it easy to deploy, manage, and scale Kubernetes applications in the AWS cloud. In this blog post, we will walk you through the step-by-step process of setting up your first EKS cluster on AWS.

1. What is EKS?

Amazon EKS is a fully managed service that simplifies the processes of launching and managing Kubernetes on AWS. EKS takes care of provisioning hardware and the Kubernetes control plane, allowing you to focus on deploying and managing your applications.

2. Prerequisites

Before setting up your EKS cluster, ensure you have the following:

  • AWS Account: Sign up for an AWS account if you don't have one already.
  • AWS CLI: Install the AWS Command Line Interface and configure it with your IAM user credentials.
  • kubectl: Install kubectl, the Kubernetes command-line tool, as it will help you communicate with the EKS cluster.
  • eksctl: This command-line tool simplifies the process of creating and managing Kubernetes clusters on AWS EKS.

3. Creating an IAM Role for EKS

  1. Login to AWS Management Console and go to the IAM service.
  2. Click on Roles and then Create role.
  3. Choose EKS as the use case and select EKS Cluster.
  4. Click on Next: Permissions and then Next: Tags to skip tagging.
  5. Finally, click on Create role and name it something like EKSClusterRole.

4. Setting Up The EKS Cluster

Next, we will create the EKS cluster using the eksctl tool. If you don’t have eksctl installed, you can find the installation instructions on the official GitHub repository.

Run the following command to create a simple EKS cluster:

eksctl create cluster --name my-eks-cluster --region us-west-2 --nodes 3
  • Replace my-eks-cluster with your desired cluster name.
  • The --region flag specifies the AWS region for the cluster.
  • The --nodes flag specifies the number of worker nodes you want in your cluster.

This command will take a few minutes to provision the cluster and the necessary resources.

5. Configuring kubectl

Once the cluster is created, you need to configure kubectl to communicate with your EKS cluster. Use the following command:

aws eks --region us-west-2 update-kubeconfig --name my-eks-cluster

Now you can test the connection by checking the nodes in your EKS cluster:

kubectl get nodes

You should see a list of your worker nodes.

6. Deploying a Sample Application to EKS

To verify that the Kubernetes setup is working correctly, let’s deploy a simple nginx application.

  1. Create a file named nginx-deployment.yaml with the following content:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
  1. Apply the deployment using kubectl:
kubectl apply -f nginx-deployment.yaml
  1. To expose the nginx deployment, create a service:
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: LoadBalancer
  ports:
    - port: 80
  selector:
    app: nginx

Save this as nginx-service.yaml and run:

kubectl apply -f nginx-service.yaml
  1. Get the external IP of the service:
kubectl get services

It will take a couple of minutes to provision the Load Balancer. Once ready, you can access the nginx application by visiting the external IP in your web browser.

7. Conclusion

Congratulations! You have successfully set up your first Kubernetes cluster on AWS EKS and deployed a sample application. EKS takes the pain out of managing Kubernetes clusters, so you can focus on building and scaling your applications.

8. Diagrams

Below is a simplified diagram illustrating the architecture of your EKS setup:

+-----------------------+
|       AWS Cloud       |
|                       |
| +-------------------+ |
| |    EKS Cluster    | |
| |                   | |
| |  +-------------+  | |
| |  |   Control   |  | |
| |  |    Plane    |  | |
| |  +-------------+  | |
| |                   | |
| |  +-------------+  | |
| |  |  Worker     |  | |
| |  |   Nodes     |  | |
| |  +-------------+  | |
| |                   | |
| +-------------------+ |
|                       |
+-----------------------+
             |
             |
  +----------------------+
  |   Load Balancer      |
  +----------------------+
             |
   +-----------------+
   |   nginx Service  |
   +-----------------+

By effectively utilizing AWS EKS, you can empower your teams to work with greater agility and operational efficiency.

Happy deploying!

Post a Comment

Previous Post Next Post