Skip to content

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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

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.

About

Create a web application using Python and containerize it using Docker and deploy it on a Kubernetes cluster (Minikube).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published