Coder Social home page Coder Social logo

hello-node's Introduction

Title: Node.js "Hello World" Application Dockerization and Kubernetes Deployment

Overview:

This project involves Dockerizing a Node.js "Hello World" application, creating a Kubernetes Helm chart for deployment, and utilizing ArgoCD for GitOps management.

prerequisites for completing the tasks outlined in the project:

  1. Dockerization: Docker Installed: Ensure Docker is installed on your local machine or the environment where you plan to build Docker images. You can download and install Docker from https://www.notion.so/Minikube-Installation-Guide-for-Ubuntu-f0778b09e52e44a0800620a699b4726f?pvs=4
  • GitHub Account: You'll need a GitHub account to clone the Node.js "Hello World" application repository and push to dockerHub.
  • DockerHub Account: Create a DockerHub account if you haven't already. You'll need this account to push your Docker images
  1. Kubernetes Deployment: Kubernetes Cluster: Set up a Kubernetes cluster where you'll deploy the Helm chart. You can use local tools like Minikube or kind for development and testing purposes, or deploy to a cloud provider like Google Kubernetes Engine (GKE), Amazon Elastic Kubernetes Service (EKS), or Microsoft Azure Kubernetes Service (AKS).

Helm Installed: Install Helm on your local machine or the environment where you'll be managing the Helm charts.


Process: 1. Dockerization:

  • Application Source: The Node.js "Hello World" application source code is hosted on GitHub at https://github.com/johnpapa/node-hello.

  • Commands:

    • Clone the application repository:

      git clone https://github.com/johnpapa/node-hello.git
    • Change directory to the cloned repository:

      cd node-hello
  • Docker Image Creation: The Docker image for the application was created using a multi-stage Dockerfile for efficiency in image creation. The Dockerfile retrieves the application source code, installs dependencies, and exposes the application on port 8000.

    Dockerfile:

    # -------------------------------- Stage 1: Build Stage -------------------------------
    FROM node:12.2.0-alpine AS build
    WORKDIR /app
    COPY . .
    RUN npm install
    RUN npm run test
    
    # ------------------------------- Stage 2: Production Stage ----------------------------
    FROM node:12.2.0-alpine AS prod
    WORKDIR /app
    COPY --from=build /app .
    EXPOSE 8000
    CMD ["npm", "start"]
    
    
  • Docker Image Push: The Docker image was pushed to DockerHub using GitHub Actions. A GitHub workflow file (build-push-image.yaml) was created in the .github/workflows directory to automate the build and push process.

    GitHub Workflow:

    name: Build then Push Docker Image
    
    on:
      push:
        branches:
          - main
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          - name: Checkout code
            uses: actions/checkout@v2
    
          - name: Login to DockerHub
            run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
    
          - name: Build and push Docker image
            uses: docker/build-push-action@v2
            with:
              context: .
              push: true
              tags: pbaloriya/hello-node:latest
              DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
    

2. Kubernetes Deployment:

  • Helm Chart Creation: A Helm chart named hello-node-chart was created for deploying the Node.js application on Kubernetes. The Helm chart includes necessary Kubernetes manifests such as deployment and service configurations. Follow here or Find commands below: https://www.notion.so/Helm-Installation-9a327f6d97964fbaa6bb981ee41889d1?pvs=4

    Helm Chart Structure:

    hello-node-chart/
    ├── charts
    ├── Chart.yaml
    ├── templates
    │   ├── deployment.yaml
    │   ├── service.yaml
    │   └── ...
    ├── values.yaml
    └── ...
    
    
  • Commands:

    • Initialize Helm in the project directory:

      helm create hello-node-chart
      
    • Modify Helm chart templates and values.yaml as required.

  • 1. ArgoCD Integration: ArgoCD was utilized for GitOps management of the Helm chart deployment on a Kubernetes cluster. ArgoCD YAML files were created to define the Helm chart deployment. argocd-application.yaml

another way 2. Kubernetes Deployment:

  • ArgoCD Integration: ArgoCD was utilized for GitOps management of the Helm chart deployment on a Kubernetes cluster. Instead of creating YAML files manually, the deployment was managed through the ArgoCD dashboard.

  • Also do:

kubectl port-forward svc/hello-node-service 9009:30009 
kubectl port-forward svc/argocd-server -n argocd 8080:443
kubectl get service
kubectl get deployment
kubectl get pod

hello-node's People

Contributors

pratibha2411 avatar johnpapa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.