Set up AWS EKS from gitAction

This entry describes the steps provided by multiple chatGPT and tested by a human (me). It demonstrates connecting two systems and touches on

  • AWS IAM
  • AWS EKS and Cloudformation
  • Git Action
  • AWS Cli

GitHub Actions · GitHub

Pre-requisite

  1. AWS Account
  2. GitHub Account

Steps

  1. Create an AWS  User and get an API key
  2. Create Git Repo  (say https://github.com/jess1sd/infra)
  3. Add a GitAction to create EKS
  4. Deploy  via GitAction

Create AWS User

  1. Go to IAM, Create User (just default setting), then add Credentials
    1. User -> Credentials -> Create API Secrets
    2. Select AWS Cli (I did not try other options)

Set up Git Access

  1. Go to Git, create a person token (User->Settings->DeveloperSettings->Personal Access Tokens)
    1. Keep this access token to use as the git password later at the git clone command

Create Git Repo and Git Action

  1. Create a Git Repo, and add Git Secrets by going to settings->Secrets and Variables
    1. create two secrets, one for the aws_key_id, and another for the aws_secret_key
  2. Create a .github/workflows folder
  3. In the .github/workflows folder, create a eks-deployment.yml file which has this content
name: Deploy EKS Cluster

on:
  push:
    branches:
      - main  # or any branch you prefer

jobs:
  deploy-eks-cluster:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: us-west-2  # change to your AWS region

    - name: Deploy EKS Cluster
      run: |
        # Install necessary CLI tools
        ARCH=amd64
        PLATFORM=$(uname -s)_$ARCH

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

        # (Optional) Verify checksum
        curl -sL "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_checksums.txt" | grep $PLATFORM | sha256sum --check

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

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

        # Create EKS Cluster
        eksctl create cluster --name my-eks-cluster --region us-west-2 --nodegroup-name my-nodes --node-type t3.medium --nodes 3
        # Add additional eksctl options as per your requirements



    - name: Configure kubectl
      run: |
        aws eks --region us-west-2 update-kubeconfig --name my-eks-cluster

While deploying, go to AWS Cloudmation or AWS EKS console to monitor progress.

Once done, to view the new EKS, set up aws on your local machine

In ~/.aws/credential, add a section for your profile (you can name the profile to anything, such as my-profile)

...
[my-profile]
aws_access_key_id = <aws-access-key-id-val>
aws_secret_access_key = <aws-secret-access-key-val>
...

Then list the new EKS cluster

$ aws eks list-clusters --profile my-profile --region us-west-2
{
    "clusters": [
        "my-eks-cluster"
    ]
}