Part4: 2-tier-app-deployment
Hi everyone! In the previous blog, we deployed a flask application through k8s. However, as we already know, deploying an application through k8 involves writing manifest files from scratch for pod, deployment, service,PVC and so on. However, all the manifest files are somewhat the same except for some changes.
What if I say we need not write these yaml files from scratch and they are readily available in the form of templates? All we have to do is edit these manifests with the values required to deploy an application.
Let us understand this in depth through practical application.
Deployment of the Flask application through helm file
Firstly, install helm through the below script.
curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null sudo apt-get install apt-transport-https --yes echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list sudo apt-get update sudo apt-get install helm
Now, helm is successfully installed. Let us move on to creating the helm chart for our application.
Let us create the directory inside which we will package the application.
Next, create a helm chart for mysql through the command
helm create mysql-chart
With this command, helm creates an nginx chart which is the default chart for any application.
Get into values.yaml template and edit according to the requirements. Here, we have modified the image to mysql's latest version and changed the port no to 3306 as mysql runs on this port. We have also added the required environment variables.
Now, let us inject these environment variables from values file to deployment file.
Next, we shall package the mysql chart through the command
helm package mysql-chart
-
We shall install the mysql chart in the current folder(./) with the name mysql-chart through the command
helm install mysql-chart ./mysql-chart
Now, let us check for all the components that are deployed through the above command
We can see that mysql deployment has been successfully created
Now, lets move on to deploying flask app through helm
Lets create the default helm chart through the command
helm create flaskapp-chart
Next we shall edit the values.yaml file according to our requirements. I have inserted the image from my dockerhub for the flask app and added environment variables .
In the environment variables, we have added the IP address of mysq's ClusterIP service
We have also editted the service section to use NodePort service.
Make the necessary changes to deployment file by injecting the environmnet varaibles and changing the port type.
We are also commenting out the liveness and readiness probe as we are not using this feature in our project
Next, make necessary changes in the service file
Package and install through helm
Let us check if all the required services are up and running
Get into the mysql container and create a table required. You can check my previous blog for more information on this.
Open the port no 30007 in the worker node's inbound rule and check if the application is running on it through worker node's IP address