The simplest way to create EKS cluster

The simplest way to create EKS cluster

EKS (Elastic Kubernetes Service) is a managed Kubernetes service provided by AWS. It takes away all of the hassles of managing and maintaining a Kubernetes cluster.

There are many different ways to set up a simple EKS cluster. Terraform (an IaC tool) provides a declarative way to setup and make changes to the infrastructure both on cloud by using providers and on-premise using VMware vCenter API. But there is a catch. Provisioning an EKS cluster using Terraform requires some hefty code amount and resource declaration (from VPC and subnets to complicated IAM policies) to create just a simple cluster with no additional addons such as CloudWatch and node autoscaling.

But there is a simple (and yet powerful tool) called eksctl. eksctl is a CLI tool developed for creating and managing EKS clusters and all of its related resources such as CloudWatch for log aggregation and node autoscaling. It also has a kubernetic way to declare your cluster resources. that means you can utilize your existing templating tool such as helm and integrate it with CI/CD piplines.

Quick Start

First, if you've never used AWS cli tools you need to create an IAM user and access key and secret key. Follow these steps:

https://repost.aws/knowledge-center/create-access-key

After seting up the AWS cli tool, you need to install eksctl

ARCH=amd64
PLATFORM=$(uname -s)_$ARCH

curl -sLO "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_$PLATFORM.tar.gz"

tar -xzf eksctl_$PLATFORM.tar.gz -C /tmp && rm eksctl_$PLATFORM.tar.gz

sudo mv /tmp/eksctl /usr/local/bin        

Simple Cluster

Creating a simple cluster is as easy as it gets. you can just use one line to create a cluster

eksctl create cluster --name simple-cluster          

This command will create a Cloudformation stack which has all of the resources needed to create an EKS cluster. It might take a few minutes to bootstrap all of the services needed. Here is a create cluster command that enables node autoscaling feature.

#Create a cluster with autoscaling feature enabled. minimum running nodes #should be 3 and maximum should 5

eksctl create cluster --name=cluster \
--nodes-min=3 \
--nodes-max=5        

Declarative Way

Eksctl has a great feature that lets you create cluster manifest like a kubernetes object. This gives us the ability to incoprate eksctl with out existing infrastructure and CICD pipline and also helm charts.

Let's create the simple cluster using eksctl ClusterConfig manifest. Create a yaml file simple-cluster.yaml

DO NOT USE THESE CODES ON PRODUCTION ENVIRONMENT

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
  name: simple-cluster
  region: us-east-1
nodeGroups:
  - name: ng-1
    desiredCapacity: 3
    instanceType: t1.micro        

The nodeGroup block let's eksctl to create a node group of 3 nodes with the instance type of t1.micro. You can also use managed nodegroups.

Amazon EKS managed nodegroups is a feature that automates the provisioning and lifecycle management of nodes (EC2 instances) for Amazon EKS Kubernetes clusters
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
  name: simple-managed-cluster
  region: us-east-1
managedNodeGroups:
  - name: managed-ng-1
    minSize: 2
    maxSize: 4
    desiredCapacity: 3
    volumeSize: 20        

The manifest above will create a cluster with managed node group of minimum 2 and maximum of 4.

Cluster on already created VPC

By using manifests above, eksctl will provision an EKS cluster on a new VPC. but what if our infrastructure has already provisioned and we want to bootstrap our cluster on our VPC and subnets.

You can refrence your VPC and subnets to the manifests and let the eksctl know that you want to bootstrap your cluster on your infra.

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
  name: cluster-1
  region: us-east-1
vpc:
  id: <your_vpc_id>
  subnets:
    public:
      <your_subnet_name>:
        id: <your_subnet_id>
    private:
      <your_private_subnet_name>:
        id: <your_private_subnet_id>
nodeGroups:
  - name: ng-1
    desiredCapacity: 3
    instanceType: t1.micro
    subnets: [<your_private_subnets_name>]        

Hope you enjoyed simple tutorial. We only just scratched the surface of eksctl. On next articles i'll explain eksctl in more detail and depth.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了