Lab 4 - Deploy application


DATE:
Friday, March 29, 2024

TAGS:
k8s
kubernetes
workshop

Kubernetes Deployment

In this lab, we will deploy the application we built in the previous lab to the Kubernetes cluster. We will create a deployment and a service for the application.

Objectives

  1. Create a docker repository for frontend and push frontend image to it
  2. Create a docker repository for backend and push backend image to it
  3. Create a deployment for the frontend application
  4. Create a deployment for the backend application
  5. Create a service for the frontend application
  6. Create a service for the backend application

Steps

Create a docker repository for frontend and push frontend image to it

On docker hub, we create an account and then create a repository for the frontend application. Here's the link to the repository we created for the frontend application: Frontend Repository

We tag the frontend image with the repository name and push it to the repository.

docker build --tag mehrshadlotfi/frontend:v1 . docker push mehrshadlotfi/frontend:v1

We follow the same steps for the backend application.

docker build --tag mehrshadlotfi/backend:v1 . docker push mehrshadlotfi/frontend:v1

Create a deployment for the frontend application

We use the following command to create a template for the deployment manifest

kubectl create deployment frontend --image=mehrshadlotfi/frontend:v1 \ --dry-run=client -o yaml > frontend-deployment.yaml

We apply our changes to the deployment manifest file and apply the deployment to the cluster.

kubectl apply -f frontend-deployment.yaml

Create a NodePort service for the frontend application

We use the following command to create a template for the service manifest

kubectl expose deployment frontend --port 3000 --type NodePort \ --dry-run=client -o yaml > frontend-service.yaml

We apply our changes to the service manifest file and apply the service to the cluster.

kubectl apply -f frontend-service.yaml

Create a deployment for the backend application

We follow the same steps as we did for the frontend application to create a deployment for the backend application.

kubectl create deployment backend --image=mehrshadlotfi/backend:v1 \ --dry-run=client -o yaml > backend-deployment.yaml kubectl apply -f backend-deployment.yaml

Create a ClusterIP service for the backend application

We follow the same steps as we did for the frontend application.

kubectl expose deployment backend --port 3000 --type ClusterIP \ --dry-run=client -o yaml > backend-service.yaml kubectl apply -f backend-service.yaml