Deploy Webapp on AKS cluster using Azure DevOps YAML pipeline

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my name is shalanda chaudhary and in this video i'll show how to deploy web application on azure kubernetes cluster using azure devops pipeline so let's start in the previous two videos i have already deployed kubernetes cluster container registry and set up the integration between them so if we'll go to the azure portal now as you can see on your screen aks demo cluster was deployed in that previous video whose link you can find in the description of this video so two nodes are created and those two nodes are added as a scale set in the load balancer if we'll go to the load balancers there is one load balancer for the kubernetes if we'll go to the end pool you can see both the two nodes are added there now the another resource is container registry if you go to the container registry there is one container registry which is created and if you go to the im access control in the role assignments the spn which was used to create kubernetes cluster has assigned the acr pull and push role for the container registry which means now aks cluster and container registry both are integrated with each other so now using the azure devops pipeline i'll deploy a sample web application into this cluster before this i would like to show the github repo which i have created for this so the name of the repo is aks app and i'll make this repo public and provide the information in the description so i've created index.html file this is the html file with the javascript code and i picked it from the google itself so it's a single page html file which i'm going to deploy there is a docker file which is created it's a very simple docker file it's pulling the ngnx image and copying the index.html file to a particular html location from where the web page can be deployed so using these two files dockerfile and the index.html image can be created now for deploying the containers or the pods into the cluster we need the yaml files so this is the yaml file which i have created it contains both the deployment section as well as the service part so the kind is deployment here so it's creating a web app nginx deployment with the replica of one which means only one part will be created and the details of the container i mentioned here web app ngnx is the name of the container and it will use the container port of 80. the container will pull the image from the container registry with the name web app and for the service there will be port mapping from 80 to 80 which is on the load balancer and on the pod side and a load balancer fronted ip will be created to access it from the internet so let's deploy it using the azure devops pipeline so i'll be using the same project youtube app service but before creating a pipeline i have to create the service connection for both kubernetes cluster as well as container registry so let's go to the project settings service connection and let's create a new connection for the container registry let's select docker registry next so the registry type is azure container registry it's loading the subscriptions so this is the only subscription for the lab so i'll just log in quickly so let's choose the container registry and name the connection name the same as the container registry grant access to all the pipelines and save this will create a service connection for azure container registry and after this i'll create the service connection for kubernetes cluster now the service connection for the acr is created let's create connection for the kubernetes next as your subscription it allows me to log in again i'll provide the credentials i'll select the cluster which is aksdemo cluster namespaces i'll leave as default and the service connection i'll use the same cluster name grant access to the pipelines and save so now the service connection for both the aks cluster and the acr are created so let's go to the pipelines and i'll create a folder before creating the pipeline like we did for the acr new folder aks app let's go to aks app create a new pipeline select the github and aks app is the repository so we can either use the starter pipeline and then configure each and every value but first we have to build an image then push the image to docker registry then upload the artifacts afterwards we'll pull the image from container registry by creating the secrets and finally the deployment in the cluster instead of that we can choose the deploy to azure community service and it will configure all the steps by itself like build and push image to the acr and deploy to key windows cluster let's select this this is my subscription let's log in again i'll select the cluster it's in existing namespace which is default container registry is demo aks acr and image name is web app which i would like to give because we have defined the image name as web app into our manifest files and the service port is 80. validate and confirm it's generating the ml file for us now it took around half a minute to generate the ml file first of all i'll make this trigger as none because i don't want to trigger this pipeline whenever i make a change in the github repo so service connection for the docker registry container registry image pull secret because the secret is not there it will be created so these are the variables which are defined and if we'll go to the build stage it's build and push it's going to the image repository docker file it's giving the location of the docker file and then tagging the image and upload it to container registry in this tab it will create and upload the manifest files and in the deploy stage the first step is to create an image pull secret the secret will be created based on the name which we have provided and the pipeline service principle has access to create the secret so it will be done automatically and then finally from the manifest file which will be created in the step the deployment and the service will be created so let's save and run it's creating the pipeline and should trigger soon it's waiting for the agent to start and soon the build process will start and timing i'll quickly show if we'll go to the container registry there are no repositories right now because we haven't uploaded any image till now looks like azure devops pipeline is impacted by a live incident as you can see here and this is the reason the build step is not triggered yet let's check the status capacity for the ubuntu image is limited in some regions okay i'm in australia and it's degraded there i'll pause the video and we'll resume once the build step has started this looks like a major issue and the pipeline has not been running for long so let's change the agent from azure hosted to self-hosted let me first cancel this edit the pipeline let me show you the self-hosted agent which i have i'll go to the settings agent pool there is a node pool which is there and i have created an agent this is done in the previous video you can find that video in the description instead of using the azure hosted agent we'll use the node pool let's go to the pool section and provide node pool and start the image same in the deployment section also and let's save it and run let's run it now so now it's using the node pool as you can see here and the agent is ready that's good now the docker command is running and it's building the image build and publish of an image is done and it has published the artifacts also so if we'll go to the container registries repository you can see the web app repository here and there is an app with the tag web app 270. now let's go to github repo and you can see the manifest folder here and there are two files deployment and the service which will be used for deploying into the azure communities cluster so let's go to the pipeline again go back we'll permit this pipeline because we are running this for the first time this is the reason it's asking for the permission again it's taken the agent as node001 it's downloading the artifacts so as you can see the secret wasn't there was not found so it has created a secret and now it's deploying to communities first it's creating service then it created the deployment which will create the pods so let's go to communities go to the pods and select the default namespace you can see there is a pod running which is in the running state so let's check this using the command line i'll open the cloud shell in a new window let's cancel this one login so first thing we have to do is get credentials for the aks cluster it's the azcli command so the command is easy aks get credentials iphone iphone resource group resource group name let's check the name this is the resource group an iphone iphone name of the cluster which is aksdemo cluster so it will create a cube config file and now we can run the cube ctl commands for the cluster so cube ctl get nodes as you can see the two nodes are there both ready so let's check cubectl getpods there is one pod running as you can see the manifest file in the deployment we have given the replicas one so one part is running it will check the service there is a web app load balancer service running which is an ip of 210 so if we'll go to the load balancer and go to the front end ips there is a new front-end ip configuration created so using this ip now this web application can be accessed from the internet so let's check take this ip and put it in the browser and perfect as you can see welcome to sample web app deployed in aks this is a sample index.html which i have taken it will change the color when you will move it here looks pretty cool right so now we have deployed our first sample web app into the aks cluster using the azure devops pipeline and in this case we even use the self-hosted agent tool so this is all for this video i hope you liked it thank you so much
Info
Channel: Shailender Choudhary
Views: 9,757
Rating: undefined out of 5
Keywords: azure, kubernetes, aks, acr, container, registry, certification, serviceprincipal, spn, roles, cks, cka
Id: iHvUs4Iu_c4
Channel Id: undefined
Length: 14min 46sec (886 seconds)
Published: Thu Feb 10 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.