Setting up EKS cluster via CLI/Terminal

Setting up EKS cluster via CLI/Terminal

Installation of eksctl, awscli , kubectl in Local system

  1. In windows

    • To install Choco
  • To bypass security

      Run Get-ExecutionPolicy.
    
      # If it returns Restricted, then run
      Set-ExecutionPolicy AllSigned or Set-ExecutionPolicy Bypass -Scope Process
    
      Set-ExecutionPolicy Bypass -Scope Process -Force;
    
      [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
    
                              (        or        )
    
      Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
    
      # To check the version
      Choco --version
    
  • Install eksctl

      choco install -y eksctl 
      eksctl version
    
  • Install kubectl

      choco install kubernetes-cli 
      kubectl version --client
    
  • Install awscli

      choco install awscli
      aws –version
    
  1. In MacOS

    • To install brew

      # Brew installer installation
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
      
      brew --version
      
    • Install eksctl

        brew install eksctl
        eksctl version
      
    • Install kubectl

        brew install kubectl
        kubectl version –client
      
    • Install awscli

        brew install awscli
        aws --version
      
  2. In Ubuntu (Linux)

    • Install kubectl

        sudo snap install kubectl --classic
      
    • Install awscli

        sudo snap install aws-cli --classic
      

Create AWS access key

  1. Open AWS console and click on your profile and go to "Security Credentials".

  2. It will open IAM. Scroll down to Access Keys and create one.

Joining EKS Cluster with Local system

Type the below command and fill the asked access key which you generated in AWS IAM,

aws configure  # to join to aws

Creation of EKS Cluster

  • With fargate

      eksctl create cluster --name demo-cluster --region us-east-1 --fargate
    
  • With Instance

      eksctl create cluster --name demo-eks --region us-east-1 --nodegroup-name my-nodes --node-type t2.micro --managed --nodes 2
    

    Below is our EKS,

    Below are Working nodes for EKS,

Create and associate IAM OIDC Provider for our EKS Cluster

# Template
eksctl utils associate-iam-oidc-provider \
    --region region-code \
    --cluster <cluter-name> \
    --approve

# Replace with region & cluster name
eksctl utils associate-iam-oidc-provider \
    --region us-east-1 \
    --cluster demo-eks \
    --approve

Confirm whether EKS is created or not

eksctl get cluster --name demo-eks --region us-east-1

To point towards particular EKS from the local system

aws eks update-kubeconfig --name demo-eks --region us-east-1

Deletion of EKS Cluster

  • With fargate

      eksctl delete cluster --name demo-cluster --region us-east-1 --fargate
    
  • With Instance

      eksctl delete cluster --name demo-eks --region us-east-1 --nodegroup-name my-nodes
    

Verify the Context:

  • Check if the context has been set correctly:

      kubectl config get-contexts
    

    Ensure that the current context is set to your AKS cluster. If not, switch to the correct context:

      kubectl config use-context <your-cluster-context>