Skip to content

Commit 30c1513

Browse files
committed
Make quickstart exec doc
1 parent c016a38 commit 30c1513

File tree

1 file changed

+105
-99
lines changed

1 file changed

+105
-99
lines changed

articles/aks/learn/quick-kubernetes-deploy-cli.md

Lines changed: 105 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
title: 'Quickstart: Deploy an Azure Kubernetes Service (AKS) cluster using Azure CLI'
33
description: Learn how to quickly deploy a Kubernetes cluster and deploy an application in Azure Kubernetes Service (AKS) using Azure CLI.
44
ms.topic: quickstart
5-
ms.date: 01/10/2024
5+
ms.date: 04/08/2024
66
author: tamram
77
ms.author: tamram
8-
9-
ms.custom: H1Hack27Feb2017, mvc, devcenter, devx-track-azurecli, mode-api
8+
ms.custom: H1Hack27Feb2017, mvc, devcenter, devx-track-azurecli, mode-api, innovation-engine, linux-related-content
109
#Customer intent: As a developer or cluster operator, I want to deploy an AKS cluster and deploy an application so I can see how to run applications using the managed Kubernetes service in Azure.
1110
---
1211

1312
# Quickstart: Deploy an Azure Kubernetes Service (AKS) cluster using Azure CLI
1413

15-
Azure Kubernetes Service (AKS) is a managed Kubernetes service that lets you quickly deploy and manage clusters. In this quickstart, you learn to:
14+
[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://ms.portal.azure.com/#view/Microsoft_Azure_CloudNative/SubscriptionSelectionPage.ReactView/tutorialKey/CreateAKSDeployment/isLearnMode~/true)
15+
16+
Azure Kubernetes Service (AKS) is a managed Kubernetes service that lets you quickly deploy and manage clusters. In this quickstart, you learn how to:
1617

1718
- Deploy an AKS cluster using the Azure CLI.
1819
- Run a sample multi-container application with a group of microservices and web front ends simulating a retail scenario.
@@ -32,74 +33,72 @@ This quickstart assumes a basic understanding of Kubernetes concepts. For more i
3233
- Make sure that the identity you're using to create your cluster has the appropriate minimum permissions. For more details on access and identity for AKS, see [Access and identity options for Azure Kubernetes Service (AKS)](../concepts-identity.md).
3334
- If you have multiple Azure subscriptions, select the appropriate subscription ID in which the resources should be billed using the [az account set](/cli/azure/account#az-account-set) command.
3435

36+
## Define environment variables
37+
38+
Define the following environment variables for use throughout this quickstart:
39+
40+
```bash
41+
export RANDOM_ID="$(openssl rand -hex 3)"
42+
export SSL_EMAIL_ADDRESS="$(az account show --query user.name --output tsv)"
43+
export MY_RESOURCE_GROUP_NAME="myAKSResourceGroup$RANDOM_ID"
44+
export REGION="westeurope"
45+
export MY_AKS_CLUSTER_NAME="myAKSCluster$RANDOM_ID"
46+
export MY_DNS_LABEL="mydnslabel$RANDOM_ID"
47+
```
48+
3549
## Create a resource group
3650

3751
An [Azure resource group][azure-resource-group] is a logical group in which Azure resources are deployed and managed. When you create a resource group, you're prompted to specify a location. This location is the storage location of your resource group metadata and where your resources run in Azure if you don't specify another region during resource creation.
3852

39-
The following example creates a resource group named *myResourceGroup* in the *eastus* location.
53+
Create a resource group using the [`az group create`][az-group-create] command.
4054

41-
Create a resource group using the [az group create][az-group-create] command.
42-
43-
```azurecli
44-
az group create --name myResourceGroup --location eastus
55+
```azurecli-interactive
56+
az group create --name $MY_RESOURCE_GROUP_NAME --location $REGION
4557
```
4658

47-
The following sample output resembles successful creation of the resource group:
48-
49-
```output
50-
{
51-
"id": "/subscriptions/<guid>/resourceGroups/myResourceGroup",
52-
"location": "eastus",
53-
"managedBy": null,
54-
"name": "myResourceGroup",
55-
"properties": {
56-
"provisioningState": "Succeeded"
57-
},
58-
"tags": null
59-
}
60-
```
59+
Results:
60+
61+
```JSON
62+
{
63+
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myAKSResourceGroupxxxxxx",
64+
"location": "eastus",
65+
"managedBy": null,
66+
"name": "testResourceGroup",
67+
"properties": {
68+
"provisioningState": "Succeeded"
69+
},
70+
"tags": null,
71+
"type": "Microsoft.Resources/resourceGroups"
72+
}
73+
```
6174

6275
## Create an AKS cluster
6376

64-
To create an AKS cluster, use the [az aks create][az-aks-create] command. The following example creates a cluster named *myAKSCluster* with one node and enables a system-assigned managed identity.
65-
66-
```azurecli
67-
az aks create \
68-
--resource-group myResourceGroup \
69-
--name myAKSCluster \
70-
--enable-managed-identity \
71-
--node-count 1 \
72-
--generate-ssh-keys
73-
```
77+
Create an AKS cluster using the [`az aks create`][az-aks-create] command.
7478

75-
After a few minutes, the command completes and returns JSON-formatted information about the cluster.
79+
```azurecli-interactive
80+
az aks create --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_AKS_CLUSTER_NAME --enable-managed-identity --node-count 1 --generate-ssh-keys
81+
```
7682

77-
> [!NOTE]
78-
> When you create a new cluster, AKS automatically creates a second resource group to store the AKS resources. For more information, see [Why are two resource groups created with AKS?](../faq.md#why-are-two-resource-groups-created-with-aks)
83+
> [!NOTE]
84+
> When you create a new cluster, AKS automatically creates a second resource group to store the AKS resources. For more information, see [Why are two resource groups created with AKS?](../faq.md#why-are-two-resource-groups-created-with-aks)
7985
8086
## Connect to the cluster
8187

82-
To manage a Kubernetes cluster, use the Kubernetes command-line client, [kubectl][kubectl]. `kubectl` is already installed if you use Azure Cloud Shell. To install `kubectl` locally, call the [az aks install-cli][az-aks-install-cli] command.
88+
To manage a Kubernetes cluster, use the Kubernetes command-line client, [kubectl][kubectl]. `kubectl` is already installed if you use Azure Cloud Shell. To install `kubectl` locally, use the [`az aks install-cli`][az-aks-install-cli] command.
8389

8490
1. Configure `kubectl` to connect to your Kubernetes cluster using the [az aks get-credentials][az-aks-get-credentials] command. This command downloads credentials and configures the Kubernetes CLI to use them.
8591

86-
```azurecli
87-
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
92+
```azurecli-interactive
93+
az aks get-credentials --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_AKS_CLUSTER_NAME
8894
```
8995
9096
1. Verify the connection to your cluster using the [kubectl get][kubectl-get] command. This command returns a list of the cluster nodes.
9197
92-
```azurecli
98+
```bash
9399
kubectl get nodes
94100
```
95101
96-
The following sample output shows the single node created in the previous steps. Make sure the node status is *Ready*.
97-
98-
```output
99-
NAME STATUS ROLES AGE VERSION
100-
aks-nodepool1-11853318-vmss000000 Ready agent 2m26s v1.27.7
101-
```
102-
103102
## Deploy the application
104103
105104
To deploy the application, you use a manifest file to create all the objects required to run the [AKS Store application](https://github.com/Azure-Samples/aks-store-demo). A [Kubernetes manifest file][kubernetes-deployment] defines a cluster's desired state, such as which container images to run. The manifest includes the following Kubernetes deployments and services:
@@ -349,67 +348,75 @@ To deploy the application, you use a manifest file to create all the objects req
349348
350349
If you create and save the YAML file locally, then you can upload the manifest file to your default directory in CloudShell by selecting the **Upload/Download files** button and selecting the file from your local file system.
351350
352-
1. Deploy the application using the [kubectl apply][kubectl-apply] command and specify the name of your YAML manifest.
351+
1. Deploy the application using the [`kubectl apply`][kubectl-apply] command and specify the name of your YAML manifest.
353352
354-
```azurecli
353+
```bash
355354
kubectl apply -f aks-store-quickstart.yaml
356355
```
357356
358-
The following sample output shows the deployments and services:
359-
360-
```output
361-
deployment.apps/rabbitmq created
362-
service/rabbitmq created
363-
deployment.apps/order-service created
364-
service/order-service created
365-
deployment.apps/product-service created
366-
service/product-service created
367-
deployment.apps/store-front created
368-
service/store-front created
369-
```
370-
371357
## Test the application
372358
373-
When the application runs, a Kubernetes service exposes the application front end to the internet. This process can take a few minutes to complete.
374-
375-
1. Check the status of the deployed pods using the [kubectl get pods][kubectl-get] command. Make sure all pods are `Running` before proceeding.
376-
377-
```console
378-
kubectl get pods
379-
```
380-
381-
1. Check for a public IP address for the store-front application. Monitor progress using the [kubectl get service][kubectl-get] command with the `--watch` argument.
382-
383-
```azurecli
384-
kubectl get service store-front --watch
385-
```
386-
387-
The **EXTERNAL-IP** output for the `store-front` service initially shows as *pending*:
388-
389-
```output
390-
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
391-
store-front LoadBalancer 10.0.100.10 <pending> 80:30025/TCP 4h4m
392-
```
393-
394-
1. Once the **EXTERNAL-IP** address changes from *pending* to an actual public IP address, use `CTRL-C` to stop the `kubectl` watch process.
395-
396-
The following sample output shows a valid public IP address assigned to the service:
397-
398-
```output
399-
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
400-
store-front LoadBalancer 10.0.100.10 20.62.159.19 80:30025/TCP 4h5m
401-
```
402-
403-
1. Open a web browser to the external IP address of your service to see the Azure Store app in action.
404-
405-
:::image type="content" source="media/quick-kubernetes-deploy-cli/aks-store-application.png" alt-text="Screenshot of AKS Store sample application." lightbox="media/quick-kubernetes-deploy-cli/aks-store-application.png":::
359+
You can validate that the application is running by visiting the public IP address or the application URL.
360+
361+
Get the application URL using the following commands:
362+
363+
```bash
364+
runtime="5 minute"
365+
endtime=$(date -ud "$runtime" +%s)
366+
while [[ $(date -u +%s) -le $endtime ]]
367+
do
368+
STATUS=$(kubectl get pods -l app=store-front -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}')
369+
echo $STATUS
370+
if [ "$STATUS" == 'True' ]
371+
then
372+
export IP_ADDRESS=$(kubectl get service store-front --output 'jsonpath={..status.loadBalancer.ingress[0].ip}')
373+
echo "Service IP Address: $IP_ADDRESS"
374+
break
375+
else
376+
sleep 10
377+
fi
378+
done
379+
```
380+
381+
```bash
382+
curl $IP_ADDRESS
383+
```
384+
385+
Results:
386+
387+
```JSON
388+
<!doctype html>
389+
<html lang="">
390+
<head>
391+
<meta charset="utf-8">
392+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
393+
<meta name="viewport" content="width=device-width,initial-scale=1">
394+
<link rel="icon" href="/favicon.ico">
395+
<title>store-front</title>
396+
<script defer="defer" src="/js/chunk-vendors.df69ae47.js"></script>
397+
<script defer="defer" src="/js/app.7e8cfbb2.js"></script>
398+
<link href="/css/app.a5dc49f6.css" rel="stylesheet">
399+
</head>
400+
<body>
401+
<div id="app"></div>
402+
</body>
403+
</html>
404+
```
405+
406+
```JSON
407+
echo "You can now visit your web server at $IP_ADDRESS"
408+
```
409+
410+
:::image type="content" source="media/quick-kubernetes-deploy-cli/aks-store-application.png" alt-text="Screenshot of AKS Store sample application." lightbox="media/quick-kubernetes-deploy-cli/aks-store-application.png":::
406411

407412
## Delete the cluster
408413

409-
If you don't plan on going through the [AKS tutorial][aks-tutorial], clean up unnecessary resources to avoid Azure charges. Call the [az group delete][az-group-delete] command to remove the resource group, container service, and all related resources.
414+
If you don't plan on going through the [AKS tutorial][aks-tutorial], clean up unnecessary resources to avoid Azure charges.
410415

411-
```azurecli
412-
az group delete --name myResourceGroup --yes --no-wait
416+
Remove the resource group, container service, and all related resources using the [`az group delete`][az-group-delete] command.
417+
418+
```azurecli-interactive
419+
az group delete --name $MY_RESOURCE_GROUP_NAME --yes --no-wait
413420
```
414421

415422
> [!NOTE]
@@ -441,4 +448,3 @@ To learn more about AKS and walk through a complete code-to-deployment example,
441448
[kubernetes-deployment]: ../concepts-clusters-workloads.md#deployments-and-yaml-manifests
442449
[aks-solution-guidance]: /azure/architecture/reference-architectures/containers/aks-start-here?toc=/azure/aks/toc.json&bc=/azure/aks/breadcrumb/toc.json
443450
[baseline-reference-architecture]: /azure/architecture/reference-architectures/containers/aks/baseline-aks?toc=/azure/aks/toc.json&bc=/azure/aks/breadcrumb/toc.json
444-

0 commit comments

Comments
 (0)