Lab 4 - Deploy application
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
- Create a docker repository for frontend and push frontend image to it
- Create a docker repository for backend and push backend image to it
- Create a deployment for the frontend application
- Create a deployment for the backend application
- Create a service for the frontend application
- 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