0
0
KubernetesHow-ToBeginner · 4 min read

How to Create an EKS Cluster in Kubernetes Quickly

To create an Amazon EKS cluster, use the eksctl command-line tool which simplifies cluster creation with a single command. Alternatively, you can use the AWS CLI to create the cluster and worker nodes manually by defining configuration files and running aws eks create-cluster commands.
📐

Syntax

The simplest way to create an EKS cluster is using eksctl. The basic syntax is:

  • eksctl create cluster --name <cluster-name> --region <region> --nodes <number-of-nodes>

Here:

  • --name: The name you want for your EKS cluster.
  • --region: AWS region where the cluster will be created.
  • --nodes: Number of worker nodes to launch.

Alternatively, using AWS CLI involves multiple steps:

  • Create a cluster with aws eks create-cluster specifying the cluster name, role ARN, and VPC config.
  • Create node groups separately with aws eks create-nodegroup.
bash
eksctl create cluster --name my-cluster --region us-west-2 --nodes 3
💻

Example

This example shows how to create a simple EKS cluster named my-cluster in the us-west-2 region with 3 worker nodes using eksctl. This command sets up the control plane, worker nodes, and networking automatically.

bash
eksctl create cluster --name my-cluster --region us-west-2 --nodes 3
Output
2024-06-01T12:00:00Z [ℹ] eksctl version 0.152.0 2024-06-01T12:00:01Z [ℹ] using region us-west-2 2024-06-01T12:00:02Z [ℹ] setting availability zones to [us-west-2a us-west-2b us-west-2c] 2024-06-01T12:00:03Z [ℹ] nodegroup "ng-1" will use "ami-0abcdef1234567890" [Amazon Linux 2] 2024-06-01T12:00:04Z [ℹ] creating cluster stack "eksctl-my-cluster-cluster" 2024-06-01T12:05:00Z [ℹ] created cluster "my-cluster" 2024-06-01T12:05:01Z [ℹ] created nodegroup "ng-1" 2024-06-01T12:10:00Z [✔] all cluster resources ready 2024-06-01T12:10:01Z [ℹ] you can now use kubectl to interact with your cluster
⚠️

Common Pitfalls

Common mistakes when creating an EKS cluster include:

  • Not having the correct IAM permissions for your AWS user or role.
  • Missing or incorrect VPC and subnet configurations causing cluster creation to fail.
  • Using outdated eksctl or AWS CLI versions that lack support for latest features.
  • Not configuring kubectl to connect to the new cluster after creation.

Example of a wrong command missing region:

bash
eksctl create cluster --name my-cluster --nodes 3

# Correct command includes region:
eksctl create cluster --name my-cluster --region us-west-2 --nodes 3
📊

Quick Reference

CommandDescription
eksctl create cluster --name --region --nodes Create EKS cluster with specified name, region, and worker nodes
aws eks create-cluster --name --role-arn --resources-vpc-config Create EKS control plane using AWS CLI
aws eks create-nodegroup --cluster-name --nodegroup-name --subnets Create worker node group separately
aws eks update-kubeconfig --name --region Configure kubectl to connect to the cluster

Key Takeaways

Use eksctl for the easiest and fastest way to create an EKS cluster.
Always specify the AWS region with the --region flag to avoid errors.
Ensure your AWS user has the right IAM permissions before creating the cluster.
After cluster creation, update your kubectl config to manage the cluster.
Check your VPC and subnet settings to prevent networking issues.