CI-CD for Azure Kubernetes Service AKS using Azure DevOps

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi developers in this video we'll learn how to create the CI and CD pipelines to deploy an application into Azure kubernetes service aks for that we'll be using visual studio team services bsts for this CI pipeline will connect to a repository on github to get the source code and the yamen files then we'll use the docker task in order to build and push the docker container into docker hub this image will be used later from the CD pipeline where here we'll get the image and deploy it to aks using the cube CTL commands this deployment right here is a bit tricky because an hour ml file we always specify the static version of our docker container for that will be used I think another task that will try to update the latest tag use it for our docker container so join me in this video to show you how we can do this so here I start from VSDs where here I'll go and create a new project so I'll say for example the project name should be angular up kubernetes then I'll hit create once that's done now I can go directly to the build section right here to start creating my CI pipeline so let's start creating a new pipeline here our specify the source code for my app which is hosted on github so by the way the app is on a github it's publicly available where you and find the source code for the empty angular app along with file for docker file and also the deployment gamma files which we'll be using today in order to deploy to aks so let's specify our let's connect to our github account and go and say authorize github once that's done now I can access to my github repos I look for the repository right here angular app kubernetes I'd go and select it so actually here you can go and fork this project if you want to start from this video but if you want to take a look at the previous videos where I showed how to create the docker file and build run and push the docker image and also deploy to Azure using the dashboard but you will be deploying using the DevOps strategy so here we choose it the project from github now and go and say continue and from here I can start from an empty template but I can also start with a template that have two tasks which is the one right here docker container this one will help me to build and push the image into docker hub so I'll select this one and here you see that the agent that was rekted is the hosted Linux preview which have the full installation of the foreign style of containers and that machine but just here you can continue with that for me I just add speak my my agent that I have created so that I can deploy faster then the first task here is build an image so to build the image here it is asking where we want to push this image we can push it to a draw container registry sar but here I'm gonna push to get to docker hub for that I used or I pick the container registry then I need to connect to docker hub for that I'd go and select a new right here and because I have already connected before here it saves my daugher ID and my password let's give a name for this connection let's call it docker connection and let's verify that our credentials were was the right ones that's verified cool now we can and here we need to specify the build for this task so this will run the docker command and we can specify which exactly which command we want to use so we'll start by building the image so we can create it then for the docker file here to look for the docker file from our app I can go and specify the docker file from my github repository so I go and pick this one so it has the docker file and now we can ow or we need to configure the image name so here I'll to configure the image name I need to add my docker ID my docker idea here if I go to my account where I have created the account it's the one displayed at the top right of my screen so I'll use this value to tag my image it will be actually used to tag the image so let's use that one good now the build task is ready to be run it then we need to we'll go to configure the push and for the push right here we go again and say we want to use docker hub instead of our SAR and then we need to specify the connection that we have already created at the previous task in order to be able to connect and push to docker hub this action will be pushing an image I'm ok with that and now for the image name again I'd go and specify the same image name that I have used inside a build task because this one will try to get the image that I already created and it will try to push it to the curb cool now I'm ready to run this pipeline but now after this CI pipeline we want to create the CD pipeline and for this CD pipeline we need to run the yamen deployment files and to kubernetes for that I need to pass boost files from here where they have access to source control I need to pass them through the CD pipeline because from the CD pipeline actually I don't have let's say I don't have access to the github repository so I'll pass them from you so how to do that I'm gonna add two tasks the first one it will copy the task or copy the files to a specific folder and the task we'll be using here is copy files - it's at that and then we'll add another task which will publish the yamen files into the draw folder which will be saved persistently so let's look for publish publish build artifacts it's next one and if we take a look at publish artifact right here by default it takes all the content publish it inside this folder which is to build artifact staging directory and it will publish it and to a folder called a drop so we can get this drop folder or we can access it from our CD pipeline so I put my Yama files inside this directory I'll do that using the copy task so from here I go and say this first folder should be where I do have my deployment here we do have to deployment EML files when use we use it inside to deploy the image and to a local kubernetes cluster and this one will deploy to an cluster hosted on a draw remember the difference between the two is the users of load balancer for this pipe the local file uses the node port so let's click on that and then let's here go and move the file and to content let's remove the two stars so the source folder is the root folder for my repository on github and then the content is this file then for the target folder here we instead want to copy this file to the file used by the published task which is the actually I should I should I copy it again then I paste it right here we build artifacts staging directory which will be copied later or published later from using the published tasks and to the drop folder good now we are ready to run this task so let's say hit save and the queue safe and the queue and let's take a look at the execution of this task so it will start by getting the source code from github then it will build the image our image here it's a docker that contains an angular application it's an empty application that shows only this page right here so we want to now to deploy it into Azure Coburn it is but unfortunately here the build fails why because if we dig into the logs right here we find that here I try to tag the image as the name right here so this is should be my docker ID then it adds the name as it gets it from my github repo so because we did say the name of the repo then it use it those two names using the two slashes and that's not allow it on a docker hub it actually here picket this name right here so to fix this just it's simple we can go back to build an image and from here we go to refresh then side build an image we want to specify a static name for our image let's say I want to call it angular app for example and we need to reuse the same name for the push an image task copy that then let's go save and EQ again and now the process was running successfully so if I go here to my github account then here the latest image was this one now if i refresh I should see a new one was added right here good now we want to deploy this image into kubernetes service on Azure for that I'll go back to our DevOps and from here I go and create the pipeline for the 3d or the release I click new pipeline in order to create the CD pipeline or the release and here I can start from an empty template but I can also choose one of those built-in templates so here I do have the templates that I want to use which is deployed to kubernetes cluster I apply this template and here it creates an environment for me so I say for example this is going to be my production environment I'm okay with that and here I can specify an artifact and the artifact is the input for my CD pipeline here we can choose from a docker hub our container registry packages in city Jenkins and so on but here I'm gonna choose the build which is the default selected one and I select my built pipeline to be the one that we already created and then I'll hit add and here our production environment contains one job and one task that is the cube CTL apply so let's configure this task right here you have the name for this task note that here we are using the v-0 and not the one of course you can choose also the one if you want here we need to specify a connection to kubernetes so for that I'd go and create a new one right here I say this uses R cube config and I say this is my kubernetes connection I need to specify the service URL and the cube config how can we get those values actually here if we go to the command line we do have a special command to get the configuration files for for for kubernetes so here I'll go and use the command cube CTL config view - - row this will generate this config files and so I need to go and copy the content of this file I'll copy it then I use it right here for the value for my cube config I'll paste it but here we still need the service URL how can we get the service URL is actually embedded here it's the one that ends with izm q8s so let's copy this value right here and we'll use it here for the service URL we'll check they accept and trusted certificates and we'll verify the connection here it says it's verified cool now I can click OK and it will take my connection then here for the name space if we keep this empty it will use the default name space but of course you can create your own name space for a testing for example we'll use the command apply and note we have also some other commands like the create delete exec and so on here we are fine with the apply command for the applying we can use the arguments inside command line but you can also use the configuration files here we'll be using the command cube CTL apply - f then the path to the Yama deployment file and from here from this entry we need to specify the path for the Yama file I can't click here to get the Yama fight that should be inside the drop folder but was generated during the CI pipeline and here it is our Yama file I click OK and then that's all the required configuration for this task in order to apply the deployment to aks we note that we have some other options useful options like creating these secrets like the connection strings for example or any secrets you use on your app we do have also config maps which will store our key values that we could use them as global environment and a global environment variables inside aks and we have also some other Advanced Options like specifying the version of kubernetes we are using great so now we have our task and DCD pipeline configure it in order to run the gamma deployment file to deploy the created docker container but if we take a look at the Yama file that we have created we can see that here we do have a little problem that is it will try to always deploy the v1 of our docker container but during the CI pipeline we have created a new image and we target it using the build ID we want to actually to deploy that in your image instead of this v1 so how can we change this value dynamically during the CD pipeline to do that here I've used a task which have the role of replacing the tokens this task is called replace tokens I go and grab this one I'll add it just before the cube City I'll apply tasks there this task is easily configured so it will look for the root directory for my file I'll go and say the root directory is the one that have its path the deployment dot ro dutiable but in this here we need to only specify the direct or the path to the folder and in the next right here we specify the target file so instead of looking for a config file I say look for my deployment of our adagiamo file then here inside the advanced set we have the the token use it as a prefix and another one use it as suffix so it will look for those two characters inside my Yama file and it will try to replace them so this means I need to use those tokens and slide the amplifier so I'll go and copy it then come in here I'll go and replace V 1 with this prefix and the same for the statics so I'd go ahead and copy it and paste it here and inside here I'll use the environment variable define it by DST s here I used the one that I have already defined to tag my image which is the build dot build ID so I'll use that now we should have a new docker image created and to see a visual state for that new docker image I go to the app component dot HTML which is inside the SRC app and here I'll go and use or I'll add just a simple static text right here that will tell me this angular app is running and in a docker container inside a drawer kubernetes service and this text is the one that will be displayed along with at this one good now let's push our changes and to github so that VSDs can get the new app version to do that I'd go and use the command line I'll go and say git add then git commit we have the command then we'll push the changes when we go here to get help go refresh we see here that the change was added then here I go I need to rerun again the CI pipeline for that I'd go and say Q we need to wait until this finishes running now that this runs successfully we can go to the curb and check if the image was added successfully so not here the latest image is eight one eight but here I should see a new image added to my docker hub account now I'm ready to go and run the release so I'll go and save this then I create a new release just a create and let's follow the log for the running execution now we can see that the deployment was done successfully so let's let's check if our edits was done successfully or not so I'll go back to the dashboard I go and refresh and here I should see that here we do have some deployment and progress so here it creates creating the angular deployment and it is still creating the last container because here we have specified five we want to create five containers so it is creating them and here it is creating the angular service let's refresh again and check the status and here it finishes creating the five containers and also the service so and here we do have the external end point from which we can access our application hosted on docker on kubernetes let's click on that and here we should get the angular of the atrophies like this one but with a new message that we have specified and here it is our angular app is running in a docker container inside our kubernetes service IKS cool now our app is deployed successfully so we can go right here and see all the resources created from the dashboard but you can also go to use the command line and here I go and say here and we can go and look for all the configuration that was created and go and say cube city had got get services then we get the list of or our angular service that we have was created with the external IP we can also go and say cube city L get pods to get our five pots or also get the deployments I hope you like it this video where we have created the CI and CD pipelines to host and a docker image and to assure kubernetes service where and the CI we have a built and push the image and to docker hub then from the CD pipeline we have applied or using the task cube CTL apply in order to use the Yama file that we have created in order to apply its configuration into either aks so thank you for watching
Info
Channel: Houssem Dellai
Views: 45,958
Rating: undefined out of 5
Keywords: docker, kubernetes, k8s, devops, ci-cd, ci, cd, vsts, azure, kubectl, microsoft, Azure DevOps
Id: K4uNl6JA7g8
Channel Id: undefined
Length: 24min 47sec (1487 seconds)
Published: Sun Sep 09 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.