Deploy an Azure Kubernetes Service (AKS) cluster and run application

by GCP Guru
187 views

Login into cloud shell on azure portal.

Create a resource group-

  1. az group create –name kapilakscluster3 –location eastus

Description: – The following example creates a resource group named kapilakscluster3 in the eastus location.

Output:-

—————————————————————————————————–

{

  “id”: “/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myAKSCluster”,

  “location”: “eastus”,

  “managedBy”: null,

  “name”: “kapilakscluster3”,

  “properties”: {

    “provisioningState”: “Succeeded”

  },

  “tags”: null

}

Create AKS cluster-

Description:- Use the az aks create command to create an AKS cluster. The following example creates a cluster named kapilakscluster3with one node.

  • az aks create –resource-group kapilakscluster3 –name kapilakscluster3 –node-count 1 –generate-ssh-keys  

After several minutes, the command completes and returns JSON-formatted information about the cluster. JSON file available in powershell window screen shot.

Connect to the cluster-

Description:- To configure kubectl to connect to your Kubernetes cluster, use the az aks get-credentials command. This step downloads credentials and configures the Kubernetes CLI to use them

  • az aks get-credentials –resource-group kapilakscluster3–name kapilakscluster3

Connect with the nodes-

Description:- To verify the connection to your cluster, use the kubectl get command to return a list of the cluster nodes. Note that this can take a few minutes to appear.

4)      kubectl get nodes

Run the application-

Description: – A Kubernetes manifest file defines a desired state for the cluster, including what container images should be running. For this example, a manifest is used to create all objects needed to run the Azure Vote application.

Create a file named azure-vote.yaml and copy into it the following YAML code. If you are working in Azure Cloud Shell, this file can be created using vi or Nano as if working on a virtual or physical system.

Use the kubectl apply command to run the application.

  • kubectl apply -f azure-vote.yaml

Test the application: –

Description:- As the application is run, a Kubernetes service is created that exposes the application front end to the internet. This process can take a few minutes to complete. To monitor progress, use the kubectl get service command with the –watch argument.

  • kubectl get service azure-vote-front –watch

Please see the external IP in command prompt- 137.117.64.102. and browse the IP and get the application.

Monitor health and logs-

Description: – If container insights monitoring has been enabled, health metrics for both the AKS cluster and pods running on the cluster are available on the AKS cluster dashboard. For more information on container health monitoring, see Monitor Azure Kubernetes Service health.

To see current status, uptime, and resource usage for the Azure Vote pods, browse back to the AKS resource, select Monitor Container Health > select the default namespace > and select Containers. It may take a few minutes for this data to populate in the Azure portal. 

Scale AKS nodes-

Description: – If you created your Kubernetes cluster using the commands in the previous tutorial, it has one node. You can adjust the number of nodes manually if you plan more or fewer container workloads on your cluster.

The following example increases the number of nodes to three in the Kubernetes cluster named myAKSCluster. The command takes a couple of minutes to complete.

  • az aks scale –resource-group=myResourceGroup –name=myAKSCluster –node-count 3

The output is similar to:

“agentPoolProfiles”: [

  {

    “count”: 3,

    “dnsPrefix”: null,

    “fqdn”: null,

    “name”: “kapilakscluster3”,

    “osDiskSizeGb”: null,

    “osType”: “Linux”,

    “ports”: null,

    “storageProfile”: “ManagedDisks”,

    “vmSize”: “Standard_D2_v2”,

    “vnetSubnetId”: null

  }

Manually scale pods-

Description: – Thus far, the Azure Vote front-end and Redis instance have been deployed, each with a single replica. To verify, run the kubectl get command.

  • kubectl get pods

Auto scale pods-

The following example uses the kubectl autoscale command to autoscale the number of pods in the azure-vote-front deployment. Here, if CPU utilization exceeds 50%, the autoscaler increases the pods to a maximum of 10.

  • kubectl autoscale deployment azure-vote-front –cpu-percent=50 –min=3 –max=10

 

Upgrade cluster: –

Use the az aks upgrade command to upgrade the cluster nodes. The following example updates the cluster to version 1.10.3.

  1. az aks upgrade –name myAKSCluster –resource-group myResourceGroup –kubernetes-version 1.10.3

Output:-

{

  “agentPoolProfiles”: [

    {

      “count”: 3,

      “maxPods”: 110,

      “name”: “nodepool1”,

      “osType”: “Linux”,

      “storageProfile”: “ManagedDisks”,

      “vmSize”: “Standard_DS1_v2”,

    }

  ],

  “dnsPrefix”: “myAKSClust-myResourceGroup-19da35”,

  “enableRbac”: false,

  “fqdn”: “myaksclust-myresourcegroup-19da35-bd54a4be.hcp.eastus.azmk8s.io”,

  “id”: “/subscriptions/<Subscription ID>/resourcegroups/myResourceGroup/providers/Microsoft.ContainerService/managedClusters/myAKSCluster”,

  “kubernetesVersion”: “1.10.3”,

  “location”: “eastus”,

  “name”: “myAKSCluster”,

  “type”: “Microsoft.ContainerService/ManagedClusters”

}

Validate Upgrade: –

Description:- Confirm that the upgrade was successful with the az aks show command.

  1. az aks show –name myAKSCluster –resource-group myResourceGroup –output table

Update Application: –

A change is made to the application, and the updated application deployed to the Kubernetes cluster.The application source code can be found inside of the azure-vote directory. Open the config_file.cfg file with any code or text editor. In this example vi is used.

  1.  vi azure-vote/azure-vote/config_file.cfg

 

Delete Cluster: –

Description:- When the cluster is no longer needed, use the az group delete command to remove the resource group, container service, and all related resources.

  1. az aks delete –resource-group kapilakscluster3 –name kapilakscluster3 –no-wait

Related Posts

1 comment

crocmall November 4, 2021 - 1:45 am

I am sure this article has touched all the internet viewers, its really really fastidious piece of writing on building up new website.
https://www.crocmall.com

Reply

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Maybe Not