DevOps, Docker

4 Mins Read

How to Containerize and Deploy a Full-Stack Application Using Docker and Kubernetes

Voiced by Amazon Polly

Containerization and orchestration of full-stack applications are becoming essential skills for developers and DevOps engineers. This step-by-step guide will take you through the process of creating a full-stack application, containerizing it using Docker, and deploying it to a Kubernetes cluster.

Become a Certified DevOps Professional, without leaving you job. Attend 8+ DevOps certification Training at less than the price of 2!

  • Experienced Authorized Instructor led Training
  • Live Hands-on Labs
Subscribe now

1. Prerequisites

Before you begin, make sure you have the following tools installed:

  • Docker: For containerizing the application.
  • js and npm: For installing dependencies and building the frontend and backend applications.
  • Minikube: A local Kubernetes cluster for testing Kubernetes deployments.
  • You can install Node.js and npm from the js official website. To verify, run the following commands:

 

2. Project Structure

The project will have the following directory structure:

Explanation of the Project Structure:

  • backend/: Contains the backend server code (Node.js).
  • frontend/: Contains the frontend code (React.js).
  • k8s/: Contains the Kubernetes configuration files for deploying both the backend and frontend.

 

3. Creating the Backend

Create a simple Node.js server in the backend/ folder:

Step 1: Create backend/package.json
Step 2: Create backend/index.js
Step 3: Install Dependencies

Navigate to the backend/ directory and run:

 

4. Creating the Frontend

Create a simple React.js application in the frontend/ folder:

Step 1: Create frontend/src/App.js

Navigate to the frontend/ directory and run

Step 2: Create frontend/src/index.js
Step 3: Create frontend/public/index.html
Step 4: Create frontend/package.json
Step 5: Install Dependencies

Navigate to the frontend/ directory and run:

 

5. Writing Dockerfiles for Backend and Frontend

Create Dockerfile for each of the backend and frontend services.

Backend Dockerfile (backend/Dockerfile)
Frontend Dockerfile (frontend/Dockerfile)

 

6. Building and Running the Application Locally

Step 1: Build Docker Images

Navigate to the root of the project and run the following commands:

Step 2: Push the images to DockerHub

Log in to DockerHub.

In the browser authenticate using dockerhub credentials.

Push the images to DockerHub.

 

7. Creating Kubernetes Deployment and Service YAMLs

Create Kubernetes configuration files for both backend and frontend services.

Backend Deployment (k8s/backend-deployment.yaml)

 

Backend Service (k8s/backend-service.yaml)

Frontend Deployment (k8s/frontend-deployment.yaml)

 

Frontend Service (k8s/frontend-service.yaml)

 

8. Deploying to Kubernetes

Step 1: Start Minikube
Step 2: Deploy the Application to Kubernetes

Apply the Kubernetes configuration files:

Step 3: Access the Application

Get the Minikube service URL:

Conclusion

By following these steps, you have successfully created a full-stack application, containerized it using Docker, and deployed it to a Kubernetes cluster. You’ve also learned various optimization techniques for Docker images. With these skills, you can now deploy complex applications more efficiently using Docker and Kubernetes.

 

Attend 8+ DevOps and Kubernetes Certification Trainings and become a Certified DevOps expert

  • Experienced Authorized Instructor led Training
  • Live Hands-on Labs
Subscribe now

About CloudThat

CloudThat is an award-winning company and the first in India to offer cloud training and consulting services worldwide. As a Microsoft Solutions Partner, AWS Advanced Tier Training Partner, and Google Cloud Platform Partner, CloudThat has empowered over 850,000 professionals through 600+ cloud certifications winning global recognition for its training excellence including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 12 awards in the last 8 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, IoT, and cutting-edge technologies like Gen AI & AI/ML. It has delivered over 500 consulting projects for 250+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.

WRITTEN BY Sruti Samatkar

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!