Deploy an Azure Kubernetes Service cluster using the Azure CLI

Azure Kubernetes Service

 
AKS is a managed Kubernetes service that lets you quickly deploy and manage clusters. A multi-container application that includes a web front end and a Redis instance is run in the cluster. You then see how to monitor the health of the cluster and pods that run your application.
 

Prerequisites

 
Azure Cloud Subscription
 
Step 1 :
 
Login to azure portal (portal.azure.com)
 
Step 2 :
 
Open cloud shell
 
Click → Cloud Shell button on the top-right menu bar
 
            
 
Step 3 :
 
Create a Resource
 
Run the code on Cloud shell
  1. az group create --name myResourceGroup --location eastus  
You get following output :
  1. {  
  2. "id": "/subscriptions/<guid>/resourceGroups/myResourceGroup",  
  3. "location": "eastus",  
  4. "managedBy": null,  
  5. "name": "myResourceGroup",  
  6. "properties": {  
  7. "provisioningState": "Succeeded"  
  8. },  
  9. "tags": null  
  10. }  
Step 4 :
 
Create Azure Kubernetes Cluster
 
Run the code
  1. az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 1 --enable-addons monitoring –generate-ssh-keys  
Step 5:
 
Connect to the Cluster
 
Run the code
  1. az aks install-cli  
Then, run the code
  1. az aks get-credentials --resource-group myResourceGroup --name myAKSCluster  
(This command downloads credentials and configures the Kubernetes CLI)
  1. kubectl get nodes  
(This command is to return a list of the cluster nodes.)
 
You get the following output :

NAME STATUS ROLES AGE VERSION
 
aks-nodepool1-31718369-0 Ready agent 6m44s v1.12.8
  1. NAME STATUS ROLES AGE VERSION  
  2. aks-nodepool1-31718369-0 Ready agent 6m44s v1.12.8  
Step 6:
 
Run the application
  1. apiVersion: apps/v1  
  2. kind: Deployment  
  3. metadata:  
  4. name: azure-vote-back  
  5. spec:  
  6. replicas: 1  
  7. selector:  
  8. matchLabels:  
  9. app: azure-vote-back  
  10. template:  
  11. metadata:  
  12. labels:  
  13. app: azure-vote-back  
  14. spec:  
  15. nodeSelector:  
  16. "beta.kubernetes.io/os": linux  
  17. containers:  
  18. - name: azure-vote-back  
  19. image: redis  
  20. resources:  
  21. requests:  
  22. cpu: 100m  
  23. memory: 128Mi  
  24. limits:  
  25. cpu: 250m  
  26. memory: 256Mi  
  27. ports:  
  28. - containerPort: 6379  
  29. name: redis  
  30. ---  
  31. apiVersion: v1  
  32. kind: Service  
  33. metadata:  
  34. name: azure-vote-back  
  35. spec:  
  36. ports:  
  37. - port: 6379  
  38. selector:  
  39. app: azure-vote-back  
  40. ---  
  41. apiVersion: apps/v1  
  42. kind: Deployment  
  43. metadata:  
  44. name: azure-vote-front  
  45. spec:  
  46. replicas: 1  
  47. selector:  
  48. matchLabels:  
  49. app: azure-vote-front  
  50. template:  
  51. metadata:  
  52. labels:  
  53. app: azure-vote-front  
  54. spec:  
  55. nodeSelector:  
  56. "beta.kubernetes.io/os": linux  
  57. containers:  
  58. - name: azure-vote-front  
  59. image: microsoft/azure-vote-front:v1  
  60. resources:  
  61. requests:  
  62. cpu: 100m  
  63. memory: 128Mi  
  64. limits:  
  65. cpu: 250m  
  66. memory: 256Mi  
  67. ports:  
  68. - containerPort: 80  
  69. env:  
  70. - name: REDIS  
  71. value: "azure-vote-back"  
  72. ---  
  73. apiVersion: v1  
  74. kind: Service  
  75. metadata:  
  76. name: azure-vote-front  
  77. spec:  
  78. type: LoadBalancer  
  79. ports:  
  80. - port: 80  
  81. selector:  
  82. app: azure-vote-front  
Step 7 :
 
Deploy the application
  1. kubectl apply -f azure-vote.yaml  
You get the following output:
  1. deployment "azure-vote-back" created  
  2. service "azure-vote-back" created  
  3. deployment "azure-vote-front" created  
  4. service "azure-vote-front" created  
Step 8:
 
Test the application
  1. kubectl get service azure-vote-front –watch  
You get the following output :
 
EXTERNAL-IP as pending.
  1. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE  
  2. azure-vote-front LoadBalancer 10.0.37.27 <pending> 80:30572/TCP 6s  
EXTERNAL-IP address changes from pending to an actual public IP address, press CTRL-C 
 
You get the following output :
  1. azure-vote-front LoadBalancer 10.0.37.27 52.179.23.131 80:30572/TCP 2m  
To see the Azure Vote app in action, open a web browser to the external IP address of your service.
 
 
Step 9 :
 
Delete the cluster
 
Use command
  1. az group delete --name myResourceGroup --yes --no-wait  

Conclusion 

 
That’s all. We have learned about deploying an Azure Kubernetes Service (AKS) cluster using the Azure CLI (Command Line Interface). I hope you understood how to deploy an Azure Kubernetes Service cluster using the Azure CLI on the Azure portal.