{"id":7197,"date":"2020-10-04T15:02:48","date_gmt":"2020-10-04T15:02:48","guid":{"rendered":"https:\/\/blog.cloudthat.com\/?p=7197"},"modified":"2024-06-25T11:10:29","modified_gmt":"2024-06-25T11:10:29","slug":"setting-up-and-configuring-an-aks-cluster-on-microsoft-azure","status":"publish","type":"blog","link":"https:\/\/www.cloudthat.com\/resources\/blog\/setting-up-and-configuring-an-aks-cluster-on-microsoft-azure","title":{"rendered":"Setting Up And Configuring An AKS Cluster On Microsoft Azure"},"content":{"rendered":"<p>In this blog, I will be showing you the steps to set up an AKS cluster on Microsoft Azure and also host a simple voting application on top of it. So, let\u2019s start with the introduction of everything that I have just mentioned.<\/p>\n<p><strong>What is an AKS Cluster, and what is it used for?<\/strong><\/p>\n<p><strong>Azure Kubernetes Service<\/strong> is a managed Kubernetes service in Microsoft Azure that lets you quickly deploy and manage Kubernetes clusters. Before AKS came into the picture, we had to manage the servers\/nodes, select an appropriate networking protocol, write scripts to configure the master and worker nodes, and manage the entire infrastructure along with it. AKS eliminated this burden by providing an easy way to manage your Kubernetes cluster even without in-depth knowledge of container orchestration. AKS supports the agile project method of software development, including Continuous Integration(CI) and Continuous Deployment(CD). Azure AKS is compliant with ISO, HIPAA, and HITRUST, thus ensuring that it\u2019s a secure and compliant service to have in your infrastructure. Scaling your infrastructure using just a couple of mouse clicks on the Azure dashboard has made it easier to work with containers. These are the major advantages of working with Azure Azure Kubernetes Service(AKS).<\/p>\n<p>So, an AKS cluster is used to host containerized applications that predominantly use Docker containers.<\/p>\n<p>If you are still reading, then you must already know what Kubernetes cluster and containers are. If you aren\u2019t sure what they are, kindly mention it in the comment section below and I can prepare another blog on those topics depending on the requirement.<\/p>\n<p>Pre-requisites for following this blog:<\/p>\n<ol>\n<li>An Azure account and a user with permissions to access Kubernetes Services.<\/li>\n<li>Basic understanding of containers and some Kubernetes commands.<\/li>\n<\/ol>\n<p>I will be providing some important information along with the steps to do the configuration. So, let\u2019s start.<\/p>\n<p><strong>Step 1.<\/strong><\/p>\n<p>Login to your Microsoft Azure account using the URL <a href=\"http:\/\/www.portal.azure.com\">www.portal.azure.com<\/a> and search for <strong>Kubernetes<\/strong> <strong>Services<\/strong> in the search box. After that, click on the service as I have shown in the below screenshot.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/kubernetes-services-image-01.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7198 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/kubernetes-services-image-01-300x121.png\" alt=\"\" width=\"600\" height=\"242\" \/><\/a><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/add-a-kube-cluster-image-03.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7201 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/add-a-kube-cluster-image-03-300x127.png\" alt=\"\" width=\"607\" height=\"257\" \/><\/a><\/p>\n<p><strong>Step 2.<\/strong><\/p>\n<p>Once the service window opens, click on \u2018+Add\u2019 dropdown button and select \u2018<strong>Add Kubernetes Cluster<\/strong>\u2019.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/add-a-kube-cluster-image-031.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7203 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/add-a-kube-cluster-image-031-300x127.png\" alt=\"\" width=\"612\" height=\"259\" \/><\/a><\/p>\n<p><strong>Step 3.<\/strong><\/p>\n<p>Fill in the details like Resource Group name, Cluster Name and Region.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/create-kube-cluster-image-04.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7204 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/create-kube-cluster-image-04-300x296.png\" alt=\"\" width=\"356\" height=\"351\" \/><\/a><\/p>\n<p><strong>Step 4.<\/strong><\/p>\n<p>Also, you can select a Kubernetes version that you require. This helps when you know that your application works perfectly with a specific version of Kubernetes. Select the Node Size and Node Count that you require. I am going to be selecting a Standard DS2 v2 and keep the Node Count to 1. You can resize the Node Count later, but you cannot change the Node Size once the cluster has been created.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/create-kube-cluster-image-05.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7206 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/create-kube-cluster-image-05-300x282.png\" alt=\"\" width=\"357\" height=\"336\" \/><\/a><\/p>\n<p><strong>Step 5.<\/strong><\/p>\n<p>You can check other tabs on the same page for various options like Node Pools, Authentication and Networking but you can keep everything with default settings and this testing will still work.<\/p>\n<p>Click on \u2018Review + Create\u2019 button.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/review-plus-create-image-06.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7207 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/review-plus-create-image-06-300x292.png\" alt=\"\" width=\"375\" height=\"365\" \/><\/a><\/p>\n<p><strong>Step 6.<\/strong><\/p>\n<p>After clicking on Review + Create, Azure will run a final validation before creating our cluster. You can see a \u2018Validation Passed\u2019 message once it\u2019s done after which you can click on \u2018Create\u2019 button at the bottom.<\/p>\n<p>It will take a couple of minutes for Azure to create your cluster. Once it\u2019s done, you will see a \u2018Your deployment is complete\u2019 message on your screen.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/create-cluster-image-07.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7208 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/create-cluster-image-07-297x300.png\" alt=\"\" width=\"376\" height=\"379\" \/><\/a><\/p>\n<p><strong>Step 7.<\/strong><\/p>\n<p>Click on \u2018Go to Resource\u2019 and the next task will be to connect to your cluster. Click on \u2018Cloud Shell\u2019 icon on top right of the page, which will open a terminal for you.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/cloudshell-open-image-09.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7210 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/cloudshell-open-image-09-300x82.png\" alt=\"\" width=\"644\" height=\"176\" \/><\/a><\/p>\n<p><strong>Step 8.<\/strong><\/p>\n<p>Select Bash from the dropdown option in the terminal. If you are opening Cloud Shell for the first time, it will ask you to create a Storage Account, but it\u2019s a one-time thing.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/cloudshell-open-image-10.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7211 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/cloudshell-open-image-10-300x106.png\" alt=\"\" width=\"647\" height=\"229\" \/><\/a><\/p>\n<p><strong>Step 9.<\/strong><\/p>\n<p>Now you need to configure the connection to your Kubernetes cluster here. It\u2019s a simple command as \u00a0shown below; using this command, you will be connecting to the Kubernetes cluster through Bash.<\/p>\n<pre class=\"lang:default decode:true \">$ az aks get-credentials --resource-group myakscluster-rg --name myakscluster-kubernetes<\/pre>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/az-command-image-11.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7212 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/az-command-image-11-300x89.png\" alt=\"\" width=\"658\" height=\"195\" \/><\/a><\/p>\n<p><strong>Step 10.<\/strong><\/p>\n<p>To verify the connection, we can use the Kubernetes command given below to see the nodes.<\/p>\n<pre class=\"lang:default decode:true \">$kubectl get nodes<\/pre>\n<p>&nbsp;<\/p>\n<p>Since we gave the minimum count as 1 for Nodes, we will see that node here. Make sure the Status of the Node is showing Ready, which means our configuration was correct.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/kubectl-get-nodes-command-image-12.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7214 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/kubectl-get-nodes-command-image-12-300x94.png\" alt=\"\" width=\"646\" height=\"202\" \/><\/a><\/p>\n<p><strong>Step 11.<\/strong><\/p>\n<p>Next, we need to configure our application, and for that we will be using a YAML file. If you are about to work on Kubernetes a lot, make sure you know your way around YAML files because it\u2019s ubiquitous in the Kubernetes world.<\/p>\n<p>So, let\u2019s create a new YAML file using Cloud Shell for our application. I will be giving the file an appropriate name, say, <em>voting-app.yaml.<\/em><\/p>\n<pre class=\"lang:default decode:true \">$ vi voting-app.yaml<\/pre>\n<p>&nbsp;<\/p>\n<p>You can get the content of the YAML file from the official Azure Github documentation <a href=\"https:\/\/github.com\/Azure-Samples\/azure-voting-app-redis\/blob\/master\/azure-vote-all-in-one-redis.yaml\">here<\/a>. I have used the same script here and saved the file as <em>voting-app.yaml<\/em>.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/kubectl-create-command-image-13.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7215 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/kubectl-create-command-image-13-300x95.png\" alt=\"\" width=\"645\" height=\"204\" \/><\/a><\/p>\n<p><strong>Step 12.<\/strong><\/p>\n<p>The next step will be to run the YAML file using Kubernetes commands. The command is a simple one and I have provided the same below. \u2018<em>kubectl create<\/em>\u2019 command basically creates everything that is mentioned in the YAML file mentioned, so you should be cautious while creating and running YAML files.<\/p>\n<p><strong><em>TIP: Similar to Linux command line, tab spaces does autocomplete in Azure Cloud Shell.<\/em><\/strong><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/created-image-14.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7216 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/created-image-14-300x94.png\" alt=\"\" width=\"596\" height=\"187\" \/><\/a><\/p>\n<p>The \u2018<em>kubectl create<\/em>\u2019 command mentioned in the previous step won\u2019t take much time to run and it will be over in 3 seconds. I have mentioned the output in the above screenshot and notice that it all says \u2018created\u2019 without any errors.<\/p>\n<p><strong>Step 14.<\/strong><\/p>\n<p>Now it\u2019s time to test the application. Please note that it will take a couple of minutes for Azure to actually deploy our application and to check the same, we can run the below command:<\/p>\n<pre class=\"lang:default decode:true \">$kubectl get service azure-vote-front \u2013watch<\/pre>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/get-service-azure-vote-front-image-16.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7217 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/get-service-azure-vote-front-image-16-300x88.png\" alt=\"\" width=\"586\" height=\"172\" \/><\/a><\/p>\n<p>If you are running this command right after the creation, you will see a \u2018pending\u2019 status under the External IP\u2019 column. I ran this command after a while; hence, it\u2019s showing the IP for me in the first run itself.<\/p>\n<p><strong>Step 15.<\/strong><\/p>\n<p>Copy the external IP; paste it in your browser and hit enter. You will be able to see a simple voting app that intakes the number of votes for cats and dogs. You can click on them and it does the counting.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/voiting-app-image-17.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7218 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/voiting-app-image-17-300x98.png\" alt=\"\" width=\"581\" height=\"190\" \/><\/a><\/p>\n<p>Simple, right? We just hosted our containerized application on Azure AKS.<\/p>\n<p><strong>Step 16.<\/strong><\/p>\n<p>This is an important step because this is where we clean up the resources that we have created to avoid unnecessary bills. You can use the portal to delete the cluster.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/cloudshell-open-image-09-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7219 aligncenter\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/cloudshell-open-image-09-1-300x272.png\" alt=\"\" width=\"350\" height=\"317\" \/><\/a><\/p>\n<p>Refresh the window and check the status changing from \u2018Deleting\u2019 to \u2018Deleted\u2019 in the Azure Activity Log.<\/p>\n<p>I hope this blog was helpful in understanding the configuration of a simple containerized app on Azure while setting up an AKS cluster.<\/p>\n<p>If you want to know more about Kubernetes and Azure services kindly check our courses <a href=\"https:\/\/cloudthat.in\/courses\/course\/kubernetes-essentials\/\">here\u00a0<\/a>and <a href=\"https:\/\/cloudthat.in\/courses\/course\/microsoft-azure-certification-bootcamp-for-az-204-developing-solutions-for-microsoft-azure\/\">here<\/a><\/p>\n<p>Please comment if you have any questions.<\/p>\n","protected":false},"author":227,"featured_media":0,"parent":0,"comment_status":"open","ping_status":"open","template":"","blog_category":[3608,3607,3624],"user_email":"sumits@cloudthat.com","published_by":"324","primary-authors":"","secondary-authors":"","acf":[],"_links":{"self":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/7197"}],"collection":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/users\/227"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/comments?post=7197"}],"version-history":[{"count":1,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/7197\/revisions"}],"predecessor-version":[{"id":46185,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/7197\/revisions\/46185"}],"wp:attachment":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/media?parent=7197"}],"wp:term":[{"taxonomy":"blog_category","embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog_category?post=7197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}