Coder Social home page Coder Social logo

web-application-deployment-using-docker-and-kubernetes's Introduction

Web-Application-Deployment-using-Docker-and-Kubernetes

Create a web application using Python. Containerize the application using Docker and deploy it on a Kubernetes cluster (Minikube). A cloud provider for hosting is optional.

Step 1: Create a Simple Web Application

We'll use a simple Node.js application as an example. You can choose any language or framework you are comfortable with.

Create a directory for your project:

mkdir simple-web-app
cd simple-web-app

Initialize a new Node.js project:

npm init -y

Install Express.js:

npm install express

Create an app.js file with the following content:

const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => {
  res.send('Hello, world!');
});

app.listen(port, () => {
  console.log(`App listening at http://localhost:${port}`);
});

Step 2: Dockerize the Application

Create a Dockerfile in your project directory with the following content:

# Use the official Node.js image as the base image
FROM node:14

# Set the working directory
WORKDIR /app

# Copy the package.json and package-lock.json files
COPY package*.json ./

# Install the dependencies
RUN npm install

# Copy the rest of the application files
COPY . .

# Expose the port the app runs on
EXPOSE 3000

# Command to run the application
CMD ["node", "app.js"]

Build the Docker image:

docker build -t simple-web-app .

Run the Docker container:

docker run -p 3000:3000 simple-web-app

Step 3: Set Up Kubernetes Cluster with Minikube

Install Minikube: Follow the instructions here.

Start Minikube:

minikube start

Step 4: Deploy the Application on Kubernetes

Create a Kubernetes deployment file deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: simple-web-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: simple-web-app
  template:
    metadata:
      labels:
        app: simple-web-app
    spec:
      containers:
      - name: simple-web-app
        image: simple-web-app:latest
        ports:
        - containerPort: 3000

Create a Kubernetes service file service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: simple-web-app
spec:
  type: NodePort
  ports:
  - port: 3000
    targetPort: 3000
    nodePort: 30001
  selector:
    app: simple-web-app

Apply the Kubernetes configurations:

kubectl apply -f deployment.yaml
kubectl apply -f service.yaml

Step 5: Access the Application

Get the Minikube IP:

minikube ip

Access your application: Open your browser and go to http://<Minikube_IP>:30001.

web-application-deployment-using-docker-and-kubernetes's People

Contributors

gabriele77s2 avatar

Watchers

 avatar

Forkers

mohitsalyan

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.