Deploying Web application to Google Kubernetes engine with explanation

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back to my channel my name is somya and I am a devops engineer I have been creating a series of lab on Google Cloud in today's video I will show how you can deploy a web application to Google's kubernetes engine so first we will take a simple web application and then we will package this web application inside the docker mage so this is a flow which we will be following in today's video we will containize this some web application in a Docker image then we'll upload this Docker image into an artifact registry later we will deploy this on a jke cluster then we will Auto scale this application using a auto scale option finally we will make this sample app available on the internet so this is a complete flow which we will be following in today's video so let's get started with the lab so before starting you need to enable the a few apis for this since we will be using a artifact registry to store our Docker image we need to enable the artifact register APA so let's go to API page click on API and services under Library type artifact registry [Music] and you need to enable this artifact registry API so this API is already enabled if you have not enabled this APA then you will get an option to enable API so click on enable APA and enable this API next we need to enable Google kubernetes engine API as well since we will be deploying the application to Cluster we need this API so search for that so you need to enable this kubernetes engine API click on this API and click on enable so this will enable the API so this API is used to build and manage the container based application so you have to enable this API let's go back to Cloud console since in this lab we'll be using the cloud shell you need to activate the Google Cloud shell so here in our Google Cloud console you can see there is an option so click on this and activate the cloud shell now Cloud shell is activated since we will be storing our image in the heart effect registry and deployed from the artifact registry we need to create a repository before creating a repository we need to set some environment variables here so first let's set project ID you can get the project ID from the dashboard it's under project info you can get your project ID just copy this and go back to your Cloud shell so here set the project ID environment variable and you can cross verify if the project ID is set properly by running Echo dollar project ID so this is my project ID so next we need to set this project ID photo Cloud CLI so to do that you need to execute command Cloud config set project project ID so now it's updated next you need to create and Repose it free so you will be running gcloud artifacts repositories create and uh you will provide your repository name your so this is the repository name my iPhone repo and the repository format you will give it as Docker and the location you will you will specify the location where this repository has to be created and will provide a description for this repository so we can execute this and if you want to check the locations you can also run gcloud RT facts locations list this will provide the location list you can choose any location you want out of this so this is how you find the location details so let me execute this command click on enter so now the repository is created next we need to build the container image so here we will deploy a sample web application called hello hap it's a web server written in go that responds to all requests with a message hello world on Port 8080. before we deploy this application to JK cluster we have to package this application as a Docker image so in order to build a Docker image we need a source code on the docker file source code contains your application code whereas a Docker file is a file which contains a set of instruction on how the image will be built so you should have your source code on Docker file in your workspace I have already downloaded the source code in my workspace this is my workspace so inside my workspace I have my source code hello iPhone app so if we CD to this this will have a Docker file as well get this Docker file so this is a simple um application written Now using go language so here we have provided a set of instruction how this image has to be built so let's build and tag this Docker image so before running this command you have to ensure that you are inside the folder where your Docker file is present so I'm inside the hello iPhone app folder so using this command we will build and tag the docker image for our Hello app so this command will instruct Docker to build the image using the docker file in the current directory and then save it to the local environment and tag it with a name so the dot represents the current directory this project ID is a variable which Associates the container image with the hello repo let's execute this so this is building our Docker image now the image is built let's clear the screen so you can execute Docker images command to verify if the build was successful so when we execute this command we can see and there is an image created with this specific tag so whatever we have mentioned in the command it has taken next we need to add IM policy bindings to the service account I have to execute this command G Cloud artifacts repositories add IM policy binding and it will provide a repository name and you will you should also give the location region where your repository is hosted and iPhone iPhone remember you will provide a service account this is a project number which you can get it from the dashboard and the project info you can get this project number you will provide that then you will add the role so here you will mention the service account the role here we are providing the artifact registry reader role here let's execute this command now the IM policy has been updated for the repository my repo next we need to upload this image to the registry before uploading the container image to the registry we have to configure the docker CLI tool to authenticate to the artifact registry so to do that we have to execute this command gcloud auth configure hyphen Docker and the region you have to provide the region so let's execute this type y now it's updated or we have to push the docker image to the repository let's check our Docker image by running the command Docker images so we will be pushing this image using Docker push to our artifact registry so here you can also give it as V1 which indicates it's a version one so let's execute this command so we have successfully pushed our Docker image to artifact registry next we need to create a jke cluster so GK is nothing but Google kubernetes engine which consists of pool of VM instances running kubernetes let's first set the compute region by running the command gcloud config set compute region and the region name execute this command once it is done you need to create a cluster type gcloud container clusters create iPhone Auto and the cluster name so here I am giving app iphone cluster as my cluster new execute this command so this will create your cluster this will take some time to create a cluster so now my cluster is created in the location Us best one and it is having three notes which are in running straight so now we are ready to deploy a Docker image to the cluster so in kubernetes applications are represented as pods and it holds one or more containers in it and we deploy this pods as a set of replicas next we will create a kubernetes deployment to run our application on this cluster and this deployment will have replicas which are nothing but pods one deployment pod contains only one container in order to deploy our application to this cluster first we need to connect to the cluster to perform any operation on the cluster you first have to connect with a cluster so you can connect to the cluster by running the command gcloud container clusters get hyphen credentials and the cluster name so I have created my cluster as app iphone cluster so I'll be providing that cluster name here followed by the region name so let's execute this command from the output you can see there is a cube config entry generated for app iphone cluster now we need to create a deployment create a deployment so you need to execute Cube CTL create deployment and the name for that followed by the image name so let's execute this command when you execute this Cube CTL get deployments you can see there is a deployment by the name hello iPhone app so this is the one which we had created just now so let's um describe this deployment followed by the deployment so this is a deployment which is created in a default namespace contains only one replica and you are you can see the Pod template so here you can see the Pod specification here now let's set the deployment replica to 3 so there is only one replica set here so let's update it to three executing the command Cube CTL scale I meant followed by the deployment name so here you will provide hyphen iPhone replicas equals to three so you are scaling your replica set to 3. so run this command now you can see it is scaled so so when we execute this Cube CTL get deployments here you can see under ready state it is showing 3 out of one so it is getting scaled let's describe the deployment again by running the cube CTL describe deployment now you can see under replicas it got updated to three now we need to create a auto scaler for these deployments so let's do that so here we are creating a horizontal pod Auto scaler so when the CPU percentage reaches 80 the minimum part it can have is one and the maximum power it can have is 5 so this is the Min and Max we are setting to our deployment when a CPU percentage is equal to 80 it has to Auto Scale based on these conditions so let's execute this command now we have created a pod Auto scaler now let's check if the pods got created by running the command Cube CTL get bots so here you can see there are three parts to our in running State and one is in pending state so so it might take few minutes for the power to get started so once the Pod is up the status will change to running let's describe one of this board copy one of this pod so each of these ports will have individual IPS assigned and these can be reached only from inside the cluster in these ports will have ephemeral IP address and these IP addresses are not static so whenever report gets crashed due to some error gke will automatically redeploy the Pod assigning a new IP address to that border so new IP address gets assigned every time pod gets crashed and a new pod is created we need a way where we can group the spots together into one static hostname and expose this group of PODS outside the cluster to the Internet so in order to fix this issue we can make use of kubernetes services so these services will group The pods into one static IP address which are reachable from any port inside the cluster so GK will also assign a DNS host name to their static IP address and this type of service in jke is called cluster IP so this service gets an IP address which are reachable only from inside the cluster and if you want to expose the service outside the cluster then you can make use of another type of service called load balancer so these ports will be reachable through the internet you can access these parts from the internet so let's expose our application to the internet using load balancer we can expose our application to the internet using load balancer by executing the command Cube CTL expose and the deployment deployment name provide a name for the service so let's give a hello hap iPhone service and we call this type of service as load balancer where we will have a common IP address which users can use to access the spots web interface and the port it will be using 80 and we'll set the Target Port as 8080 so here iPhone iPhone Port refers to the port number which is configured on the load balancer i i iPhone Target iPhone port is the port number which the container is listening to The Container where our application is hosted so let's execute this command so now it is exposed so let's check the details about this service by executing man Cube CTL get service there are two services so yellow hyphen have hyphen service is the one which we had created just now and the external IP show is still pending let's refresh this so now the external IP is available now the ports are exposed to the internet through a kubernetes service called load balancer copy this external IP and open it in a browser so here you can see there is a Hello World message you can find the hostname or is serving the HTTP request to this browser this is the Pod name this is the pod which is serving our HTTP request so now we have deployed our application to the cluster next we'll see how we can upgrade our application to a new version and build that application and deploy to the new Docker image to the cluster again in gke we have a rolling update feature which lets us update a deployment without downtime so during this rolling update the cluster will incrementally replace existing odds with the pods containing the docker image for the new version during this update load balancer will ensure that it routes traffic only to the available ports let's update our code so we'll open the editor so here I will be making some changes like here I have updated the version to two so it is displaying hello world and the version as one I'm just updating this version to two so here I have updated this so I've done with the update now let's build and tag this I will execute Docker build to build and tag this new Hello app Docker image let me execute this so here as you can see I have set the Hello app colon V2 so this is my new version so now it's building an image now it has successfully built a new Docker image so let's push this image to the artifact registry let's list the image using Docker images so this is a new image which got created and it is having a veto tag now let's push this image to the artifact registry by executing the command Docker push followed by the image name let's execute this next we need to update our kubernetes deployment to use this new Docker image so let's do that so here we will apply a rolling update to our existing deployment so let's do that by running Cube CTL set image and deployment followed by the deployment name so here we are updating our deployment to use the new image which we had created just now so let's execute this command so now it has been updated so we can watch this update by running watch Cube CTL get bots so here you can see ports are getting updated execute Cube CTL get services and we'll copy this external IP and open it in a web browser so now you can see Hello World message and the version it is showing it as two so now our deployment is referring to the new Docker image which we had updated so that's it we are done with our lab so in today's video we learned how to containize the application and deploy it on a jke cluster also we had the seen how to auto skill this deployment and how to make use of rolling update to update our application I hope this video was helpful if you found this video helpful please like And subscribe to my channel and stay up to date with the latest content on Google Cloud once again thank you all for watching
Info
Channel: techgalary
Views: 6,955
Rating: undefined out of 5
Keywords: cloud, learn technology, google gcp, google cloud, deploy webapplication, Deploying Web application to Google Kubernetes engine, deploying web application to google kubernetes engine, cloud computing, cloud technologies, gcp exam, gcp associate exam, google associate exam, cloud engineer, google kubernetes e, google kubernetes engine, google kubernetes engine tutorial, google kubernetes engine (gke), google container registry, sample website deploy to gke, gke, gke tutorial
Id: cQeCi2hT3is
Channel Id: undefined
Length: 19min 8sec (1148 seconds)
Published: Wed Apr 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.