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
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
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
First, we can create the secret.yaml file.
- To see the detailed information of the secret we can describe it using the below command.
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
- 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.
# If you don't know what is the cluster name then use the below command
kubectl config current-context
- Delete the pod and deploy and create it again.
- Create the deployment file again using the same method.
Next, we can apply or create all the deployment files at a time using the below command.
We can also add this load balancer or your DNS provider (wherever you have registered your domain) and access the website.
- 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