AZ-204 - Develop Azure Compute Solutions - Container Groups and Kubernetes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] now earlier on we had seen a use case wherein you could go ahead and use docker compose to go ahead and deploy multiple containers so this is a technology that's available with docker when it comes to azure they have another service that is known as azure container groups so over here also you can go ahead and deploy a collection of containers here the containers get scheduled on the same host machine the containers in the container group actually share the life cycle the resources the local network and the storage volumes now the deployment of the container group can be done via a resource manager template or a yaml file and from the perspective of the exam it's important to understand the deployment via a yaml file so over here the entire service is used to go ahead and deploy a set of containers that will be running on the azure container instance service remember this service will automatic good and provision the underlying compute infrastructure right for running your containers now in the next set of chapters we are going to go through some use case scenarios which are important from an exam perspective when it comes to azir container groups now the first thing i want to show you before we actually go ahead and deploy a container using the azure container group is how to create a custom image when it comes to a image that is already available for my sequel so we've looked at docker compose we have seen at how you can actually go ahead and send out initialization data for your mysql database so if you want to go ahead and create a table if you want to go ahead and insert data you can go ahead and use doc compose now you could also go ahead and use docker compose when it comes to azure container groups but when it comes to the exams you'll normally be using the yaml configuration for the deployment of azure container groups so over there there's a different outline on how you specify statements the yammer configuration is different when it comes to azure container groups so the first thing i want to show you is how you can create a custom my sequel image so that you can actually go ahead and use that as your image when you want to go ahead and deploy a custom mysql container over here i have a folder this is on my local machine in that folder again i have a sql script over here the same thing creating a table and inserting data into the table over here i have a dockerfile now in the dockerfile i'm seeing please go ahead and use the mysql image which is available from dockerhub has the base over here i am specifying what should be the mysql root password and what should be the name of the database to create and then over here i'm using the copy command to go ahead and copy my sql script onto the entry point remember this is the entry point which is run when the container is first launched so over here now i'm creating my own custom image which has everything in place my data already in place so over here we are going to go ahead and use these commands to create that custom image so over here on the ubuntu session on my local machine i'm in my m t slash c slash temp to folder so over here let me go on to the custom my sequel folder over here i have my docker file in place so i'll go ahead and first build now an image based on the instructions in that docker file so it's done now let me go ahead and run a container based on an image i want to go ahead and verify that the image is working as it should so i want to go ahead and connect on to a running container now over here i can see that i have an error in place and that's probably because i already have some containers running in the background so let me go ahead and first stop all of my running containers so i'll go on to docker containers stop and over here nine 9790 and the other one is three seven one four all right so three seven one four and nine seven nine zero now let me go ahead and try to run it again now i should already be having that actually container in place let me go ahead and do a docker ps hyphen a so i already have my custom sql container in place the only thing it's not running so let's go ahead and start that container so start over here i'll say custom sql so the name should be app sequel sorry my mistake right so now we have the container in place now i can actually go ahead and interactively log into the container right so now i'm in the container now let me do a mysql and log into my sequel and let me confirm so let me go ahead and use appdb let me go ahead and select star from courses sorry from course and over here you can see our data in place so we now know that our custom image is working as it should now i want to go ahead and publish the image that we just create on to azure container history so i have a hd running in seo so over here if i do a docker image ls over here i can see my custom sql image in place so the first thing i'll do is to go ahead and tag my custom sql image then i need to go ahead and log into azure container registry from here so for that i'm first going to go on to the microsoft documentation to go ahead and install the azios cli basically on linux so i'll go on to the ubuntu section and over here i'll just go ahead and copy paste the commands which are required to go ahead and basically install the required packages so going on with the second package as well so it's a simple copy paste from the microsoft documentation i'll go on to the next just copy it from here paste it in my session hit on enter go back do a copy from here hit on enter then go ahead and again copy these statements and now it will go ahead and install the seo cli let's wait till this is complete now once this is complete let me go ahead and just clear the screen now over here let me do an easy login over here i'll say go ahead and use device code so now in order to authenticate onto azure cli i'm going to go ahead on to microsoft.com device login and i'll go ahead and manually enter this code i'm going on to microsoft.com device login over here i'll enter the code so i've entered the code i'll go on to next so i'll go ahead and choose my account so it's saying i'm logged in so over here also i can see that i've logged in now let me go ahead and push the image onto the azure container registry so i'll go ahead and again clear the screen and let me go ahead and push my image now i need to go ahead and log into my azure container registry so i'll do an azacr login and i have to give the name for my registry so over here in azure i have this as the registry name so let me go ahead and choose this registry name once i've logged in now let me go ahead and push my custom image on to my azure container registry now once this is done if i go on to repositories over here i can see my custom sql image in place so now in the last chapter i talked about azir container groups now let's go ahead and see how we can use a yaml deployment to go and create an azure container instance within an azure container group so again remember the azure container group is nothing but a collection of containers within the azure container instance itself now i'll go ahead and start simple we just go ahead and deploy one container as part of our container group and then in the next chapter we'll go ahead and see how to deploy two containers as part of an azure container group so again there is a particular definition that you need to follow when it comes to yaml when it comes to the azure container group basically what are the name value pairs in the yaml configuration so firstly is the name that is going to be given to your azure container instance itself then in the properties you go ahead and mention your containers over here it is giving a name for the container and then in the properties you're going ahead and specifying what is the image so earlier on remember that we did go ahead and create a custom image in one of our registries so if i go on to my repositories so over here i can see my custom sql image in place so we're going in and using that same image over here then in the resources section i'm saying please go ahead and allocate one cpu and 1.5 gigs in terms of memory and i'm saying please export port 3306. over here i'm saying please use the underlying os as linux that is the compute that will be used for hosting my container and then you need to go ahead and give what are the credentials for your registry because the azir contain instance needs to go ahead and pick it up from the azure container registry so for that you actually have to go on to your access keys for your registry over here you can actually go ahead and copy the login server what is the username and the password so that's what i've done i've gone ahead and copied the server name what is the name of my registry what is my username and what is the password now let's go ahead and deploy this yaml file so now in another tab i've gone on to azure cloud shell let me go ahead and upload that file so i'm going ahead and choosing the containers db yam alpha i'll go ahead and click on open right so i have the file over here then i'm going to go ahead and issue the command of easy container create over here i'm mentioning the resource group for my container instance and then in the file i'm mentioning the name of my yaml file let me go ahead and hit on enter so remember in the end it's still going to go ahead and create an azure container instance over here we're going in and giving a yaml definition for the creation of this azure container instance let's come back once the deployment is complete now once the deployment is complete so in another tab if i go on to all resources over here if i go ahead and search for instance so over here now i can see i have my app group container instance in place so remember the name that you gave over here will go ahead and give the name for your azure container instance over here if i go on to containers i can see that my container is running let me go ahead and just hide this over here i can go on to the properties i can see the properties of the container if i go ahead on to connect over here let me go ahead and hit connect so over here i can actually go ahead and log into my sql and over here we can see or you can see that we are connected so in this chapter just want to kind of go ahead and show you how you can do a simple deployment wire a yaml configuration this is known as deployment of azure container groups now in the last chapter we had gone ahead and seen how we could go ahead and deploy a simple container instance with just one container using a yaml deployment now in this chapter let's go ahead and see how we can do deployment of multiple containers using yaml to an azure container instance basically onto an azure container instance group so firstly let me go ahead and delete the existing group that we have in place so let me go ahead and hit on delete this is the one that we create in the last chapter right so let's go back on to our yaml configuration so over here we have again the name of our azure container instance group again in the properties we have the containers so i have my database container and now over here if you go ahead and scroll down i'm going in and giving a name for another container in the properties i'm actually going ahead and mentioning now what is the image repository for the web application asp.net core web application that will actually go ahead and connect onto this my sql database server over here again in terms of the resources i'm giving the same amount of resources over here i'm saying please go ahead and expose port 80 when it comes to the container again the os type is linux now in the ip address i am saying please go ahead and also associate a public ip address on to the azure container instance group and over here i am saying please go ahead and expose port 80 and the rest remains the same now when it comes to my application so i've already gone ahead and ensured that i have deployed basically that has an image onto my azure container registry so something that we've also seen in earlier chapters so if i go on to my container registry if i go on to my repositories so over here i have that sql app in place now if i go back on to my program so again this is the same program that is used to go ahead and display a list of courses connecting onto a mysql database server over here the most important thing that i've noted is that i need to go ahead and understand what is the value i need to go ahead and give on to the server because if you go and if you don't give a proper value for the server over here when you go ahead and actually try to connect onto the mysql database it'll go ahead and give an error of an unknown host now obviously depending upon the platform so remember docker has a different way of exposing containers then you have kubernetes then now you have azure container instances so again there's a different way in which they go out and expose their containers so over here this is through r d basically i've understood that in order to go ahead and actually connect on to the my sequel database server i need to go ahead and mention localhost and because these containers are actually running on the same host machine so your as your container group in the end remember goes ahead and deploys your containers within the group on the same host machine so i can go ahead and mention locals host basically has my server so this will actually go ahead and point on to that same compute instance that is hosting my mysql database itself so this is the most important thing when it comes to the connection string what is a server that you need to connect to this is important otherwise everything else remains the same so i've gone ahead and published this particular asp.net code application has an image onto my repository so now let's go ahead let me go on to azure cli let me go ahead and clear the screen now let me go ahead and upload the other file as well so now i'll choose containers app so over here let me go ahead and rename this as containers app.yaml and let me go ahead and hit on enter so now remember over here our azure container group will actually contain two instances one is for our database and the other is for our application let's come back once this is complete now once the deployment is complete in all resources in another tab let me go ahead and hit on refresh over here so again i can see my app group in place if i go on to my containers so let me go ahead and hide this so i can see both are in the running state so if i go ahead on to the overview let me go ahead and take the public ip address let me go on to the ip address itself in another tab and over here you can see asp.net core application it is going ahead and connecting on to the my sequel database to go ahead and get the information now when it comes to debugging so the best way to go at and debug if something is going wrong so you can go ahead and basically you know attach on to the container to go ahead and see the logs also in the azure portal if you go on to your containers if you go ahead on to the logs so over here you can see all of the logs in place you just have to go ahead and choose your container so if you go ahead and choose your web container so you'll see the logs for your web container over here so if there are any issues if there are any exceptions you will see it over here so you can actually go ahead and debug what's happening in your containers via the logs over here hi and welcome back now in this chapter i want to go ahead and show you how you can use the azure container instance to persist data onto a volume so in our case let's say we want to go ahead and run an asp.net core application has a container in azure container instances let's say this application is going ahead and downloading a blob from a storage account so remember again in the concept of containers the data in the container is not persisted when the container is deleted then the data is also not present but with azure container instance you can go ahead and persist that data over here you can actually go ahead and create a file share in an azure storage account and the container can go and mount a volume using that file share so now all the data can actually be stored in the file share itself so for persisting data azure container instance has support for using file shares so let's see how we can accomplish this so over here i have a simple consolebase.net core application this application is going ahead and getting a blob from a storage account so in azure i have a storage account in place over here i have a data container and in the container i have a file known as courses.json over here if i go on to edit i can see the contents of the file so all this program is doing is that it's going out and using the connection string of that storage account going on to the container taking the courses.json file and it will go ahead and download the file now over here when it comes to the path so i'm going to go ahead and show you the yaml configuration for the azure container group that we're going to go ahead and deploy and over there we're going to go ahead and specify this has the mount point that'll actually point onto a file share the first thing i am going to do is that let me go ahead and publish this onto an azure container registry so in azure i have an azure container registry in place currently i just have two repositories over here so let me go ahead and publish my project over here i'll choose docker container history i'll go on to next i'll choose as your container registry over here let me go ahead and choose the registry and hit on finish and then let me go ahead and hit on publish so this will go ahead and publish our project has an image on to the azure container registry now once the deployment is done if i go ahead and hit on refresh in my repositories over here i can see my image in place now over here let me go on to visual studio code i'll go on to the containers.yaml file that i will be using for deploying my azure container group so over here i'm giving the name of the group over here in terms of the properties i'm going at and giving a name for the container over here i'm seeing to go ahead and pick up basically the container from my azure container registry let me go ahead and ensure that i have the correct name for the azure container registry over here the name of the image is blob project it's the latest tag over here now in terms of the volume mounts i am saying please go ahead and use a file share volume so this is the name i have given on to the volumes which i have defined in my volume section over here so here is where i specify the mount path has app data so i'm storing that downward blob onto the mount point that is app data now if i go on to the volumes over here i'm giving a name for the volume i'm specifying the volume is based on the azure file share over here i have to go ahead and create a file share so what i can do is that i can go actually on to the same storage account just for the purpose of this demo i'll go on to file shares over here let me go ahead and create a new file share so it needs to be container share so over here i'll give the name of container share and a quota and let me go ahead and hit on create now next and to give the name of the storage account and what is the storage account key that will be used for authorization so let me go ahead on to the storage account i'll go on to access keys so over here let me go ahead and copy the storage account name so i'll place it over here then i'll go ahead and copy either key one or key two so i'll copy key one i'll go ahead and replace it over here and next is what are the credentials to connect onto the azure container registry so i'll go on to my azure container registry so i'll go on to my azure container registry i'll go on to access keys over here let me go ahead and take the login server name and let me replace it over here then i'll take the username and the password so i'll take the username from here and i'll copy it over here and take the password so over here this is the password so i'll replace this entire thing right so let me go ahead and save everything so now quickly if i go on to my storage account so if i go on to the file shares if i go on to container share so currently i can't see any files in place now in another tab i have azir cloud shell in place let me go ahead and just clear the screen now let me go ahead and upload that yaml configuration file so i'm going on to my local directory over here i'll go on to container group file share and let me go ahead and upload the containers.yaml file then let me go ahead and create that container instance using this yaml file right so this will go ahead and create the container instance let's come back once this is complete now once the deployment is complete i'll go on to a new tab over here let me go ahead and search for instance so i can see my app group container instance over here let me go on to my containers so over here it's terminal then that's fine that's because it just had to go ahead and download a block it did not do anything else if i go on to the log so over here you can see that whatever i wrote to the console is being shown in the logs over here if you actually go on to the properties and if you go ahead and scroll down over here you can see the volumes that have been mounted so you have an azure file share and now if i go onto the file share and if i go ahead and hit on refresh i can see my courses.json file so over here we are now going ahead and persisting data for the container using an azure file share now in this chapter i want to show you how you can securely go ahead and access secrets within your containers now earlier on we had seen how we could go ahead and basically download a blob onto a file share so we had gone ahead and mounted a volume now in that previous program we were going ahead and using a connection string to go ahead and connect onto a storage account but let's say i don't want to go ahead and embed the connection string within my program i want it to be has a secret in my azure container group and i want to go ahead and have the ability to go ahead and pick up the secret at runtime and then go ahead and run my program so over here if you look at my program i don't have now the connection string in place over here let me go ahead and just change the name of the block onto courses.json that's what we had looked at earlier on and over here now i'm making a reference on to a secret which will be available based on my azure container group so i'll be seeing this a little bit later on over here this is how i'm going to go ahead and get the value of the secret so the secret of storage connection is going to go ahead and hold the connection string for my storage account then within my program i am just going ahead and reading the storage connection secret over here it will be stored as a file so over here that storage connection file is going to go ahead and have the storage connection string for my azure storage account and then everything remains the same so the first thing i am going to do is to go ahead and do some cleanup first of all in my file share let me go ahead and delete this file because i'm going to go ahead and run the program again then i'll go on to my container group let me go ahead and delete this container group then let me go ahead on to my container registry so i'll go on to my app registry i'll go on to my repositories let me go ahead and delete this repository of blob project and over here in visual studio let me go ahead and publish this onto the azure container registry so here i'll go ahead and choose docker container history i'll go on to next i'll choose azure container registry i'll go on to next over here i'll go ahead and choose the application registry and over here let me go ahead and hit on publish now once the publish is complete if i go on to my repositories and i click on refresh so over here i can see again my image in place now over here in visual studio code so i have another yaml configuration file for the deployment of my container group so over here i'm giving the name of the container group again i'm going ahead and specifying what is the repository from where to pick up my image so again over here let me ensure that i have the correct name for the container registry in place over here this is my image now in addition to the volume mounts path we have over here i also have now another mount path for storing the secrets as well so over here i have another volume with the name of volume secret so if i go ahead and scroll down over here in my volumes over here the name of my volume is volume secret and over here i need to go ahead and give what is the name of the secret i want to go ahead and store so i want to go ahead and store the connection string so what is the connection string that i want to go ahead and store so if i go on to my storage account if i go on to access keys if i go and show the keys so i want to go ahead and store now this connection string but if you go ahead and look at the value over here so this value is basically in encoded format so we have to go ahead and first encode the connection string and then store the value over here now before i go ahead and do this let me go ahead and ensure to update all of these contents so that it reflects the details of my storage account and my azure container registry so once i've gone ahead and made all of the required changes let's go ahead and get now an encoded version of our connection string so over here i have a powershell script that we can actually go ahead and create the encoded version of the connection string so over here let me go ahead and get the current value of the connection string so i'll go on to my storage account i'll go ahead and copy the connection string over here i'll paste it in the value next we are going in and getting basically the bytes of the connection string then we are going in and converting it on to base64 encoding and then we can go ahead and write the value and that value we can go and write it has a secret onto our azure container group deployment so let me go ahead and copy this now i can go on to azir cloud shell that i have in another tab so let me go ahead and right click and paste that particular value then i'll go ahead and get the bytes then i'll get the base64 string and then let me go ahead and write the value right so let me go ahead and now copy this and i'll go on to visual studio code and i'll replace it over here so this is a requirement if you want to go ahead and store the secrets this is how you would store the required value you would then go ahead and automatically get the actual connection string you don't need to go ahead and you know decipher the bytes again decipher the strings no this will be done automatically for you so now let me go ahead on to my azure cloud shell now over here let me go ahead and again clear the screen now over here i already have a containers.yaml file so let me go ahead and delete that file so i don't have it anymore now let me go ahead and upload my containers.yaml file so i'll go on to container group secrets i'll go on to my containers.yaml file and let me go ahead and again do the deployment so over here remember the biggest difference is that our program is going to go ahead and now get the connection string which is stored has a secret in azure container groups then it will go ahead and follow the same process where it will go ahead and download a blob and store it in our file share now once the deployment is complete if i go on to my storage account let me go on to file shares i'll go on to my container share and over here again we can see our courses.json file so remember over here we did not have the connection string in our program it caught the connection string via a secret from the azir container group hi and welcome back now in the next set of chapters we are going to be looking at how we can deploy containers onto azure kubernetes now azure kubernetes is just a managed version of the kubernetes tool itself so kubernetes is actually used to go ahead and manage containers at scale and as your kubernetes is just a managed service for kubernetes itself on his yaw so companies will actually go ahead and develop applications has a lot of containers and once you start having many containers in place trying to go out and manage them is quite a challenge even for me if i'm developing a very simple application that just contains two or three containers trying to manage all of them when it comes to deployment when it comes to scaling when it comes to ensuring they're always up and running can be a challenge so then you can go ahead and use the kubernetes tool this tool can be used to go ahead and deploy your containers at scale it can also go ahead and perform other features such as load balancing request onto your containers it also has the ability to go ahead and ensure containers are always up and running so kubernetes can be used to orchestrate your containers for hosting your applications so your application might have different containers so it might have one container that is hosting the web layer of your application one more container that is hosting the logging part of your application let's say another container that is hosting mysql and another container just for hosting the business layer and this comprises of your application you can actually go ahead and deploy those containers has an application onto something known as a kubernetes cluster the cluster is responsible for ensuring that these containers run on underlying nodes so when your application contains many containers instead of trying to go ahead and deploy them one by one you can go ahead and deploy them has a set has an application on to your cluster now if you look at a kubernetes cluster so if we just look at the different parts of a cluster you have something known as the master node and then you have the other nodes that are used for hosting your containers the kubernetes service or the kubernetes software will actually be installed on both the master node and the other nodes as well these nodes are basically virtual machines so in azure these virtual machines are going to be managed for you even the master node is going to be managed for you as well when you go ahead and create a cluster all you go ahead and do is tell what should be the configuration of these nodes so what should be the instance type how many nodes do you want to go ahead and spin up as part of your cluster so all of your containers are actually going to be running on these individual nodes the master node is used to just go ahead and ensure that the nodes do the required work of hosting the containers all of the calls on to the cluster so let's say you're submitting an application to be deployed has containers that call is actually made onto the master node the master node will then go ahead and redirect the request onto the nodes in the cluster there are many parts of the master node so there is the api server so i said all of the calls onto the cluster goes to the api server you have something known has hcd which is the cluster store that is used to go ahead and store the state of the cluster and when you look at the different things that are actually installed on the individual nodes so you have cubelet so this is a kubernetes agent that runs on the node it's responsible for registering the node with the master node it takes the commands from the master node for deployment of the containers on the node you also have the container runtime this is used to actually take the image and deploy them as containers on the node and then you have q proxy this is used for managing the networking aspects of the container so let's thought to go and give you an overall picture first of kubernetes itself before we actually dwell into azir kubernetes so now before we actually go ahead create our kubernetes cluster and deploy our containers let's just have some quick short chapters on some important terms when it comes to kubernetes so first is the deployment of containers so over here if you're looking at a unit of deployment of a container then it is referred to has a pod so the pod actually becomes part of something known as a deployment and that deployment is done on a node in the cluster over here the unit of the deployment the initial unit of a deployment is called a pod now a pod is used to group either one or more containers so you could either have one container has part of the port or multiple containers you can just go ahead and just have one container has part of a pod the pod gets shared storage and network resources if you do go ahead and deploy multiple containers as part of a pod then they need to go ahead and listen on different port numbers because each part gets an internal ip address so if you want to go ahead and have multiple containers that are listening for request then they need to go ahead and listen on different port numbers right so in this chapter i just wanna have a quick review of the concept when it comes to a pod now in the last chapter i just quickly gone through the concept of the pod now the pod can be part of a deployment now the deployment is basically a declarative way to describe the state of the pod and the replica sets in the kubernetes cluster there's something known as a deployment controller that is used to ensure that the desired state of the environment is always met and this is something that is very important this is something that makes kubernetes very unique so for example let's say you add a very simple application that is running has a container let's say you're one single container it's basically a web application that is being hosted in this container let's say this is part of a pod now let's say if you have a lot of requests and they need to be load balanced across let's say multiple parts that are hosting the same type of container so this is like load balancing your requests across different instances of your application so kubernetes has the ability to go ahead and load balance the request across different ports in your deployment now when it comes to the deployment you can say that i want basically a minimum of three parts that are always running if in case one part goes down for any reason whatsoever the deployment controller will go ahead and quickly spin up a new pod you don't have to go ahead and tell it to spin up the new port because you've gone ahead and mentioned this as part of the deployment the deployment controller has its states over here is used to ensure that the desired state of the environment is always met and over here if you go ahead and mention the desired state of the environment to be three it will always ensure that three parts are running now in this chapter let's go ahead and deploy a kubernetes cluster so over here in all resources let me go ahead and click on add so over here let me go ahead and search for the service so i'll go ahead and choose kubernetes service i'll go ahead and hit on create now over here i'm going to go ahead and create a new group so the reason i am creating a new group is because the deployment does create a lot of resources because it will go ahead and create the underlying nodes each node has a network interface so there are artifacts that actually get deployed and let's go ahead and deploy it onto a separate resource group so i'll go ahead and hit on okay now over here let's go ahead and give a name for the cluster so we'll go ahead and deploy a cluster of nodes i'll leave the region has it is just for this point in time i do want to go ahead and spread this across availability zones if you want higher availability for the nodes of your cluster you can go ahead and use availability nodes i'll go ahead and choose what is the default version it is giving me for kubernetes then i'll go ahead and scroll down now over here you can actually go ahead and decide what is the size of the node remember this is a managed service right so all of your containers are going to be deployed by kubernetes onto these nodes so these nodes over here you can go ahead and choose what should be the size of the node and how many nodes do you want since this is just a demo i'll go ahead and just choose one node if you want you can go ahead and change the size of the note i'll just leave it as it is over here you can actually go ahead and basically choose the integration with an azure container registry so over here i do have a registry in place so let me go ahead and choose that so over here if i go on to another tab i can see my azure container registry now let me go on to next for the node pools so it'll go ahead and create one node pool which has basically one node of that node size you can go ahead right now or even later on create additional node pools now i'll leave everything as it is i'll go on to next for authentication i'll leave everything as it is over here i'll go on to next for networking so accept the defaults when it comes networking go on to integration so to go ahead and create a log antics workspace when it comes to monitoring i'll leave it as it is i'll go on tags i'll go on to review and create and let me go ahead and hit on create now it might take around 10 minutes or less for the cluster to be in place so let's come back once this is complete now once your cluster is in place you can go ahead on to the resource now over here you can actually go ahead and deploy your ports has workloads over here right so you have your deployments you have your pods you have replica sets etc and then you can also go ahead and deploy something known as services right so at the moment let's mark an end onto this chapter wherein we have gone ahead and deployed our cluster now in the last chapter we had gone ahead and deployed an azir kubernetes cluster now in this chapter let's go ahead and perform a simple deployment wherein we are going ahead and deploying containers based on the nginx image so over here i have a yaml deployment file in place we can actually go ahead and submit this gammel deployment file onto our cluster and then we'll have nginx containers in place over here i'm going in and specifying what this file is going to do so this yaml file is basically going to go ahead and do a deployment and then you have metadata about the deployment over here we're giving a name for the deployment you can actually go ahead and attach a label onto this deployment these labels can also be used for other artifacts in your deployment as well so at the moment i'm keeping a very simple label so this is a name pair of values over here we have the name as app and over here the value has engine x then i'm going ahead and now giving the specification of the pod that will be part of the deployment over here i am saying i want to have three replicas of the board in place over here again i am going ahead and specifying that same label then if you go ahead and scroll down here is where you go and specify what is a container that needs to be deployed over here i'm giving the name of the container and over here if you want to go ahead and use a specific version of nginx let's go ahead and use the latest version of nginx now i can go ahead and copy all of this i can go on to my cluster over here i can go on to workloads and then i can go ahead and click on add so over here i can go ahead and paste in the yaml deployment and let me go ahead and click on add over here right so it's going ahead with the deployment let's wait till this is complete now i waited for a minute or two let me go ahead and hit on refresh and now i can see my nginx deployment in place if you go ahead on to the deployment over here you can see the number of replicas there are three that are desired there are three that are updated there are three in total and there are three that are available if you actually go ahead and scroll down you can see all of the ports running over here if you go on to the events you'll see all the events that are pertained onto the deployment so currently we have gone ahead and deployed basically pods onto a cluster these parts are just running a single container that is based on the nginx image now in the previous chapter we had gone ahead and defined a replica set of three parts there we were going ahead and creating containers based on the nginx image now let's say that you want to go ahead and now hit these containers from the outside world you want to go ahead and have the ability to reach the nginx homepage so now you have to go ahead and basically create a service in front of this deployment now there are different types of services in place when it comes to kubernetes you can go and use the load balancer has a service the load balancer will be allocated a public ip address so then you can go ahead and make request on the public ip address and this service will automatically go ahead and load balance request across the three boards again to go ahead and deploy a service we're going to go ahead and use a yaml configuration file so over here i have a very simple service deployment over here the kind of deployment over here now is a service again i'm giving a name for the service over here the type of service is the load balancer over here i'm going and specifying what port we should be listing on that's port 80 and over here i am selecting basically my label so remember i had gone ahead and specified basically labels for the pod deployment we can go ahead and now reference that same label over here so let me go ahead and copy all of this now let me go back on to my cluster i'll go on to services let me go ahead and add a service i'll go ahead and specify the deployment and over here i'll specify the yaml code and let me go ahead and click on add right so let's wait till this is complete this will just take a couple of minutes now after waiting for a couple of minutes let me go ahead and hit on refresh and i can see my engine x service in place i can now see it has also been allocate an external ip address so let me go ahead and click on this and over here you can see the home page so now my requests are being directed onto my internet deployment so if you want to go ahead and expose your ports onto the outside world you can go ahead and create a service now in this chapter i want to go through the deployment now of two containers onto our kubernetes cluster so one container will be based on the custom mysql image we had built early on we had gone ahead and sent that on to the azir container registry and over here i have the dotnet application which you have seen before that is used to go ahead and basically connect onto the mysql database now over here in the connection string so i have the user has the root the password has azure at the 8123 and database has appdb now over here my server is my sql and i'll go ahead and explain this later on because i said understanding the host to connect to is very important well the first thing i want to do is to go ahead and publish this as an image onto my azure container registry so i do have an azure container registry in place let me go on to the repositories so over here i have my custom sql image in place so let me go ahead and publish this on to the container registry so i'll choose docker container registry and hit on next i'll go ahead and choose as your container registry and hit on next i'll choose my registry and hit on finish and now let me go ahead and hit on publish so let's wait till this is complete now once the publish is complete if i go ahead and hit on refresh so i can see my sql app image in place now let me go on to visual studio code now over here i have a mysql.yaml file this will be used for the deployment of the mysql containers in our kubernetes cluster and then i have an app.yaml file this will actually go ahead and deploy our.net core application first let me go on to the mysql deployment file now over here i have two things in the file first is a deployment of a service and the other is the deployment of our pods so over here in the deployment of the parts everything remains the same the only difference is that i'm going ahead and making a reference on to our custom sql image in our azure container registry over here in terms of the labels i'm going in and giving a label of app and my sql over here in terms of the service i am going at an exposing port 3306 but over here i am not going ahead and using a load balancer because i want to go ahead and use a load balancer for my app.gamma file and not for my mysql database deployment so it will still go ahead and expose this service so that we can go ahead and connect onto the service from our app.yaml based application deployment so over here the name of the service i'm giving is my sequel and that's why in the visual studio code if i go on to my course service class over here the server i'm giving is basically the name of the service i'm deploying and that's my sequel so that's from where i got the name right so this is from the mysql deployment if i go onto my app.yaml file so over here i have a deployment for my application over here the container port is port 80. over here i'm making a reference onto the dotnet core application deployment we just made has an image onto the azure container registry and then i'm going ahead and using now a load balancer has a service and i'm going and exposing port 80 so let's go ahead and deploy these workloads so i'll go on to the mysql yaml file i'll copy everything i'll go on to my cluster now what i'll do is that the first thing i'll do is to go ahead and delete the existing internet service and workload that i have so i'll go on to my service i'll go ahead and hit on delete so i'll confirm the delete process then i go on to my workload and let me go ahead and delete the nginx deployment once this is done now let me go ahead and add a workload and in the yaml file i can go ahead and add both the service deployment and the deployment itself of the pods let me go ahead and click on add so it's going in and creating basically two one is a deployment and the other is a service let me just wait for a minute or two now after waiting for a minute or two let me go ahead and hit on refresh so i can see my my sequel deployment is complete if i go on to the services i have the mysql service in place now let me go ahead on to my app.yaml file i'll copy everything let me go ahead and again add a workload so let me go ahead and click on add over here let me go ahead and add the yaml configuration and click on add over here so it's going at and creating the deployment and the service so let's come back after a minute or two now i wait for a minute or two let me go ahead and hit on refresh so i can see my my app pod basically in the ready state if i go on to my services i can see my app service also in the ready state let me go ahead and open the external ip address and over here you can see the list of services right so we have gone ahead and seen how we can do now our application deployment onto the kubernetes cluster now in this chapter i just briefly want to go through the cube ctl tool so this is a tool that is actually already available within kubernetes this can be used to go ahead and issue commands against your cluster so in the earlier chapter we already have seen how to go ahead and deploy a cluster we went and also deployed a service and a workload basically a deployment now over here in azure cloud shell let me go ahead and just clear the screen now over here i have some commands in place the first command is to go ahead and get the credentials of the cluster using the easy aks command so this is the azure kubernetes commands for azure command line over here you have to go ahead and give the name of the cluster now our cluster is part of a different resource group so if i go on to the overview it's basically part of the kubernetes group so let me go ahead and copy that let me go ahead and place it over here so this will allow us to go ahead and interact with the cluster so over here let me right click and paste the command right so that is there now you can actually go ahead and issue different commands so if you want to go ahead and look at the nodes that are running has part of the cluster you can go ahead and issue the cube ctl get nodes command you can also get all of the parts over here you can see a one node that is running if you want to go ahead and look at all of the pods you can go ahead and do that as well so you can see your three ports that are running next if you want to go ahead and look at your deployments so that is also possible so you have three deployments in place if you want to go ahead and look at your services so you have one deployment in place if you want to go ahead and look at your services you can go ahead and see your service so you can see the load balancer service that we have now please know that using cube cdl ax you can go ahead and also manage various aspects of your cluster so you can go ahead and deploy your pods you can go ahead and deploy your services you can go ahead and delete your pods you can go ahead and delete your services you can go ahead and issue commands against your cluster using cube ctl now in this chapter i just want to quickly go through the logging aspect when it comes to azure kubernetes so when you go ahead and create your kubernetes cluster it will actually go ahead as part of the wizard and also create a log antics workspace that log antics workspace will actually go ahead and take all the logs about your containers about your nodes etc so if you actually go on to all resources if you go ahead and actually create a cluster i just want to go ahead and show you where this setting is during the creation so i'll go ahead and choose kubernetes service so i'll just quickly go ahead and choose the details i'll leave everything as it is i'll go onto next for node pools so leave everything as it is i'll go on to the last section which is integrations and over here you can see that when it comes to container monitoring by default it is enabled and it will go ahead and send the logs on to a log addict's workspace so it'll actually go ahead and create that lock antics workspace for you so in another tab i already have a cluster running so i have some containers that are also running has part of the cluster now if i go on to all resources if i go ahead and just search for log so i want to go on to the log antics workspace that gets created for this cluster now over here if i go ahead and scroll onto the log section let me go ahead and just hide this over here you will see now the tables when it comes to container insights so when you go on to container log here is where you can actually go ahead and see the logs about your container so if you actually go ahead and type in container log so just a table itself let me go ahead and just hide this and click on run and over here you will see all of the rows of data so for each data over here you can see the time that it was generated on which node it is actually running so remember these are running on your underlying nodes over here you can see the container id and other aspects as well now just for the purpose of the exam i'm just going to go ahead on to a few statements when it comes to the logs itself and yes i said i do know that as your kubernetes is not an objective in the exam but then i still saw a question based on logging when i gave the exam so i just want to ensure that you are prepared so over here in the first statement i just want to go ahead and look at the data in the container log where the time generated was greater than the timestamp over here so i'm just declaring a variable over here saying that i want to go ahead and basically look at the information in the past one day in the last 24 hours so if i go ahead and just run the statement quickly over here and let me go ahead and hit on run so i'm getting the data so this is the data for the past 24 hours now the next statement that i have is i want to get all of the container ids now over here the container ids will be in the table of cube port inventory so remember all of your containers are part of pods and the information about the container ids and the parts is there basically in the container log but the container id itself all of them are basically in the cube port inventory and over here i'm seeing where basically i want to get the containers based on my cluster and i want to get all of the distinct container ids so over here if i go ahead and just run this statement now right so i'm getting all of the distinct container ids please note that this will also go ahead and represent the system containers that are also running now next i'm trying to go ahead and now combine the queries so over here i'm saying please now go ahead and get the logs of the containers where the container id is basically in the containers id that i got over here so now let me go ahead and copy these statements i'll go over here and i don't need now the container ids over here because i'm already going ahead and basically making a reference onto container ids over here so let me go ahead and click on run let me go ahead and sorry select everything and then click on run right so we're getting the data in place now finally i'm going a step further wherein i want to go ahead and look at all the data based on the computer so i'm summarizing the count by the computer so remember this is the underlying nodes in the cluster so let me go ahead delete everything enter the statement and then click on run so now you can see the containers are just basically running on one node because i only have one node in my cluster now i said the purpose of this was just to go ahead and explain some of the queries which you can go ahead and use when it comes to querying your containers so again we're not going to go into depth because i said this is a one-off scenario when this comes to purely an exam perspective about understanding logging when it comes to azure kubernetes
Info
Channel: Alan Rodrigues
Views: 1,148
Rating: undefined out of 5
Keywords: AZ-204, Kubernetes
Id: 5msb4qcjBrU
Channel Id: undefined
Length: 71min 41sec (4301 seconds)
Published: Thu Oct 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.