Spinning Up a Kubernetes Cluster on AWS EKS¶
The process of creating a Kubernetes cluster on Amazon Web Services (AWS) using Amazon Elastic Kubernetes Service (EKS). Kubernetes is an open-source container orchestration platform that helps manage containerized applications and services. Amazon EKS simplifies the setup and management of Kubernetes clusters, allowing you to focus on deploying and managing your applications.
Prerequisites¶
Before you begin, ensure you have the following prerequisites in place:
-
AWS Account: You need an active AWS account with necessary permissions to create resources like EKS clusters, IAM roles, VPC, etc.
-
AWS CLI: Install and configure the AWS Command Line Interface (CLI) on your local machine. You can download it from the AWS CLI Documentation.
-
kubectl: Install
kubectl
, the Kubernetes command-line tool, to interact with your cluster. You can follow the installation instructions in the Kubernetes Documentation. -
IAM User: Create an AWS IAM user with programmatic access and necessary permissions (e.g., AmazonEKSClusterPolicy, AmazonEKSServicePolicy). Note down the user's access key ID and secret access key. Document Link
-
Key Pair (Optional): If you plan to SSH into your worker nodes, create an EC2 key pair or use an existing one. This can be done through the AWS Management Console.
Steps to Create an EKS Cluster¶
Step1: Install AWS CLI¶
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
choco install awscli
aws --version
Step 2: Configure the AWS CLI with the IAM user's access key ID and secret access key:¶
aws configure
Step 3: Install Kubectl¶
curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.23.17/2023-10-17/bin/linux/amd64/kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
choco install kubernetes-cli --version=1.23.4
kubectl version --client
Step 4: Install eksctl¶
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl version
choco install -y eksctl
eksctl version
Step 5: Create an EKS Cluster¶
Here are all the commands:
Command 1: Create an EKS Cluster¶
eksctl create cluster --name <cluster-name> --version <k8s-version> --region <region> --nodegroup-name <nodegroup-name> --node-type <node-type> --nodes <node-count> --nodes-min <min-nodes> --nodes-max <max-nodes>
Example:
eksctl create cluster --name kube-app --version 1.24 --region eu-central-1 --nodegroup-name kube-node-demo --node-type t2.micro --nodes 2 --nodes-min 2 --nodes-max 3
Command 2: Get Information About Nodes¶
kubectl get nodes
After setting up your EKS Cluster, go ahead and deploy my coffeeshop website for a warm-up. Enjoy the deployment! ☕🚀
https://softwarelife.github.io/devops/k8s/exercise01/#website-deployment
Command 3: Update Node Group Maximum Nodes and Minimum Nodes¶
eksctl update nodegroup --cluster=<cluster-name> --region=<region> --name=<nodegroup-name> --nodes-min=<min-nodes> --nodes-max=<max-nodes>
Example:
eksctl update nodegroup --cluster kube-app --region eu-central-1 --name kube-app --nodes-min=1 --nodes-max=2
Command 4: Scale Node Group¶
eksctl scale nodegroup --cluster <cluster-name> --region <region> --name <nodegroup-name> --nodes <desired-nodes>
Example:
eksctl scale nodegroup --cluster kube-app --region eu-central-1 --name kube-app --nodes 2
Command 5: Get Node Group Details¶
eksctl get nodegroup --region <region> --name <nodegroup-name> --cluster <cluster-name>
Example:
eksctl get nodegroup --region eu-central-1 --name kube-app --cluster kube-app
Command 6: Delete EKS Cluster¶
eksctl delete cluster --name <cluster-name> --region <region>
Example:
eksctl delete cluster --name kube-app --region eu-central-1