Deploy nodejs app to EKS using GitHub Actions

In this article we are going to cover How to Deploy nodejs app to EKS using GitHub Actions | Build and Deploy to Kubernetes using GitHub Actions | Automatic deploy to Kubernetes with GitHub Action.

Prerequisites:

  • AWS Account with Admin Previleges
  • GitHub Account

Step #1:Create Amazon EKS cluster using eksctl

Please follow below article to Create Amazon EKS cluster using eksctl.

How to Create Amazon EKS cluster using eksctl

Step #2:Create Amazon Elastic Container Registry (ECR)

Go to your AWS account and create new ECR as shown below

Deploy nodejs app to EKS using GitHub Actions 1

Deploy nodejs app to EKS using GitHub Actions

Step #3:GitHub Actions workflow Deploy to Kubernetes

Now we need to create new GiHub Repository and push the code.

So this is my GiHub Repo of Deploy nodejs app to EKS using GitHub Actions so you can clone our repo

Here is your workflow to Deploy nodejs app to EKS using GitHub Actions.

name: Node js app deploy to EKS
on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v3

    - name: Install kubectl
      uses: azure/[email protected]
      with:
        version: 'v1.27.0' # default is latest stable
      id: install

    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: ap-south-1

    - name: Login to Amazon ECR
      id: login-ecr
      uses: aws-actions/amazon-ecr-login@v1

    - name: Build, tag, and push docker image to Amazon ECR
      env:
        REGISTRY: ${{ steps.login-ecr.outputs.registry }}
        REPOSITORY: devopshint
        IMAGE_TAG: 1.1
      run: |
        docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
        docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG

    - name: Update kube config
      run: aws eks update-kubeconfig --name devops-cluster
    
    - name: Deploy to EKS
      run: |
        kubectl apply -f deployment.yaml
        kubectl apply -f service.yaml

Step #4:Create Secret in GitHub Repository

So here we need to create two secrets here

  1. AWS ACCESS KEY ID
  2. AWS SECRET ACCESS KEY ID
Deploy nodejs app to EKS using GitHub Actions 2

Step #5:Check nodes, service and pods

To check the details about your node run the below command

kubectl get nodes
kubectl get pods
Deploy nodejs app to EKS using GitHub Actions 3
kubectl get svc
Deploy nodejs app to EKS using GitHub Actions 4

Step #6:Access Nodejs app on browser using LoadBalancer

copy the External IP of nodejs and hit on your browser

Deploy nodejs app to EKS using GitHub Actions 5

Conclusion:

In this article we have covered How to Deploy nodejs app to EKS using GitHub Actions | Build and Deploy to Kubernetes using GitHub Actions | Automatic deploy to Kubernetes with GitHub Actions.

Shweta Mamidwar

I am Shweta Mamidwar working as a Intern in Product Company. Likes to share knowledge.

2 thoughts on “Deploy nodejs app to EKS using GitHub Actions”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap