Coder Social home page Coder Social logo

devops_assi_2's Introduction

DevOps Engineer Assignment-2 Submission

Introduction

Welcome to my submission for the DevOps Engineer assignment -2. In this repository, you'll find all the necessary files and documentation related to the assignment requirements.

Assignment Description

To prepare the provided Node.js codebase for deployment on a local Kubernetes cluster, I followed the following several steps:

First, Download the source code & Unzip the folder in your local machine

image

Second, Dockerize the Node.js Application:

Dockerizing your application involves creating a Docker image that contains your Node.js application along with its dependencies.

Now I'll be able to run my application in containers, which can then be deployed to Kubernetes.

image

Adiitionaly we can use :-

docker build -t hello-node-image .

to build docker image image

Next use:- docker run -p 3000:3000 hello-node-image

This command maps port 3000 of the container to port 3000 of your localhost. Now we can access our Node.js application at http://localhost:3000 to check our docker image is working fine or not. image

Third, Create Kubernetes Deployment and Service YAML files

You'll need to create YAML files for Deployment and Service. Deployment YAML will specify how many instances of your application should run, image

while Service YAML will expose your application to other services within the Kubernetes cluster. image

Deploy to Kubernetes

Make sure you have a local Kubernetes cluster(in my case Minikube) set up & running in the background, then you can deploy your application using kubectl: Run the commands

kubectl apply -f deployment.yaml

kubectl apply -f service.yaml

After executing these commands, your Node.js application should be deployed to your local Kubernetes cluster.

Note:- Make sure to adjust configurations as per your requirements and your Kubernetes cluster setup.

Fourth, To implement Horizontal Pod Autoscaling (HPA) for the deployed application, you'll need to configure HPA in addition to the Deployment and Service configurations. Here's how I did this:

  1. Enable Metrics Server Horizontal Pod Autoscaler requires metrics from the Metrics Server to function properly. Ensure that the Metrics Server is deployed and running in your Kubernetes cluster. If not installed, install using:- kubectl apply-f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml image

  2. Update Deployment YAML Update your Deployment YAML file to include resource requests and limits for CPU and memory. This will allow Kubernetes to monitor my resource usage. image

  3. Create Horizontal Pod Autoscaler (HPA) YAML Create an HPA YAML file to define the autoscaling behavior. image

  4. Apply Changes Apply the changes to your Kubernetes cluster using kubectl apply:

kubectl apply -f deployment.yaml

kubectl apply -f service.yaml

kubectl apply -f hpa.yaml

Fifth, To define resource limitations (CPU and RAM) for the deployed application pods, we need to set resource requests and limits in the Deployment YAML file.

This will allow Kubernetes to allocate resources appropriately and prevent resource starvation or contention.

Here's how I specifed resource limitations in my Deployment YAML: image In this configuration:

requests specify the minimum amount of resources that the container requires. & limits specify the maximum amount of resources that the container is allowed to use.

After updating the Deployment YAML with resource limitations, you can apply the changes to your Kubernetes cluster:

kubectl apply -f deployment.yaml

This ensures that each pod running my Node.js application works to the specified resource limitations, preventing resource contention and ensuring stable performance of my application.

Sixth, To simulate increased traffic and stress test my application using hey (a load testing tool), I followed these steps:

  1. Install hey First if haven't already, you need to install hey. You can find installation instructions in the hey GitHub repository: https://github.com/rakyll/hey#install I have a mac with homebrew installed so I installed it easily using brew install hey.

  2. Determine Load Parameters Decide on the load parameters you want to simulate, such as the number of requests (-n), the concurrency level (-c), and any additional options you want to use.

  3. Run Load Test Run hey with the desired parameters to stress test your application. For example: I ran using :-

hey -n 1000 -c 50 http://your-nodejs-app-url/ This command sends 1000 requests with a concurrency level of 50 to the specified URL.(in my case it's http://localhost:3000/ ) image

  1. Analyze Results Once the load test completes, hey will display various metrics such as requests per second, latency statistics, and errors encountered. Analyze these metrics to understand how your application performs under load.

Example Load Test Here's another example of a load test command using hey:

hey -n 2000 -c 150 http://localhost:3000/ & Observe how it responds image -n 2000: Specifies 2000 total requests to be made. -c 150: Sets the concurrency level to 150, meaning 150 requests will be made concurrently.

You can adjust the parameters according to your specific testing requirements and the expected traffic load on your application.

devops_assi_2's People

Contributors

vaibhavmalhotra002 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.