Part4: 2-tier-app-deployment

·

3 min read

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

  1. 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.

  2. Let us create the directory inside which we will package the application.

  3. 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.

  4. 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.

  5. Now, let us inject these environment variables from values file to deployment file.

  6. Next, we shall package the mysql chart through the command helm package mysql-chart

  7. We shall install the mysql chart in the current folder(./) with the name mysql-chart through the command helm install mysql-chart ./mysql-chart

  8. 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

  1. Lets create the default helm chart through the command helm create flaskapp-chart

  2. 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 .

  3. In the environment variables, we have added the IP address of mysq's ClusterIP service

  4. We have also editted the service section to use NodePort service.

  5. Make the necessary changes to deployment file by injecting the environmnet varaibles and changing the port type.

  6. We are also commenting out the liveness and readiness probe as we are not using this feature in our project

  7. Next, make necessary changes in the service file

  8. Package and install through helm

  9. Let us check if all the required services are up and running

  10. Get into the mysql container and create a table required. You can check my previous blog for more information on this.

  11. 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

Thus application successfully packaged and deployed through helm