Deploy Containerized Application on K8s Cluster.

Fawaz C P
4 min readDec 17, 2023

--

In this project, we will see how to deploy a containerized web application on k8s cluster

Steps

  • Create Kubernetes cluster
  • Create EBS volume for DB pod
  • Label the nodes with zone names (we will create EBS volume in a zone)
  • Kubernetes definition files to create our objects on the k8s cluster.

Step 1️⃣

  • Create k8s cluster using Kops

To set up k8s cluster with Kops click the link below 👇

Once the cluster is ready we can create an EBS volume using CLI.

Step 2️⃣

  • Create EBS volume for DB pod and label it
# use the below command to create an EBS volume (make sure to change the region and AZ where you want to create EBS volume)

aws ec2 create-volume --availability-zone=us-east-1a --size=3 --volume-type=gp3
Copy the volume ID and keep it somewhere because we need to add the volume ID in the definition file

We have to make sure when running our db pod that the EBS volume we created is in the same zone as the node. To confirm the node AZ we can use the below command.

kubectl describe node i-0b5bec9a1812c8ffc | grep us-east-1

Next, we can create a custom label in the same zone. To do that enter the below command

Make sure to change the node ID and the zone. You can do the same for other nodes as well after checking the AZ of that node

Step 3️⃣

  • Create a definition files

All the definition files are there in the GitHub repo by Imran Teli. We need to clone that repo into the k8s cluster.

# use the below command on your ec2 instance where you have created the cluster to clone the project repo

git clone https://github.com/imranvisualpath/kube-app.git
Now we can see all the definition files in the repo.

First, we can create the secret.yaml file.

  • To see the detailed information of the secret we can describe it using the below command.
We have encoded the secrets so that it is not exposed to anyone. To see the secrets you can decode it and see.

­Next, let’s create mysql db deployment. Before creating the db deployment file we need to add the EBS volume ID we created in the definition file and also change AZ where you have created the EBS volume

Open vprodbdep.yaml file and make the below changes
Change the zone and EBS volume ID as per your volume
  • If we describe the pod we created now we can see there is some error. The error is because we have not tagged the EBS volume we created. To do that go to the AWS console and open the volume created then tag it with your cluster name.
Make sure the volume is in the available state.
Under value, you need to add your cluster name.
# If you don't know what is the cluster name then use the below command

kubectl config current-context
Add this name to the EBS volume then save.
  • Delete the pod and deploy and create it again.
  • Create the deployment file again using the same method.
Now we can see the pod is up and running successfully

Next, we can apply or create all the deployment files at a time using the below command.

Make sure you are in the deployment file directory and use the above command. This will create all the files we have added in the current directory
Wait for some time copy the load balancer DNS and open it in a new browser and we will be able to see the website.

We can also add this load balancer or your DNS provider (wherever you have registered your domain) and access the website.

Select the load balancer and click on Create Record.
  • Wait for some time and access the domain and we will be able to access the website through this domain

Clean Up 🧹

This project is part of a Udemy course by Imran Teli. To get a better understanding of this project and the definition files we used you can enroll in the course by clicking here

Thank you!🤗

--

--

Fawaz C P

Cloud Engineer | AWS Community Builder | Enthusiastic in learning and adapting new skills.