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 a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.

CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 650k+ professionals in 500+ cloud certifications and completed 300+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training PartnerAWS Migration PartnerAWS Data and Analytics PartnerAWS DevOps Competency PartnerAWS GenAI Competency PartnerAmazon QuickSight Service Delivery PartnerAmazon EKS Service Delivery Partner AWS Microsoft Workload PartnersAmazon EC2 Service Delivery PartnerAmazon ECS Service Delivery PartnerAWS Glue Service Delivery PartnerAmazon Redshift Service Delivery PartnerAWS Control Tower Service Delivery PartnerAWS WAF Service Delivery Partner and many more.

To get started, go through our Consultancy page and Managed Services PackageCloudThat’s offerings.

 

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!