Skip to content

Commit 3cb1efa

Browse files
Merge pull request #271507 from schaffererin/execdoclinuxcliquickstart
Execdoclinuxcliquickstart
2 parents 84f4436 + c353c2e commit 3cb1efa

File tree

1 file changed

+104
-105
lines changed

1 file changed

+104
-105
lines changed

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

Lines changed: 104 additions & 105 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/09/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://go.microsoft.com/fwlink/?linkid=2262758)
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,71 @@ 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

35-
## Create a resource group
36-
37-
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.
36+
## Define environment variables
3837

39-
The following example creates a resource group named *myResourceGroup* in the *eastus* location.
38+
Define the following environment variables for use throughout this quickstart:
4039

41-
Create a resource group using the [az group create][az-group-create] command.
40+
```azurecli-interactive
41+
export RANDOM_ID="$(openssl rand -hex 3)"
42+
export MY_RESOURCE_GROUP_NAME="myAKSResourceGroup$RANDOM_ID"
43+
export REGION="westeurope"
44+
export MY_AKS_CLUSTER_NAME="myAKSCluster$RANDOM_ID"
45+
export MY_DNS_LABEL="mydnslabel$RANDOM_ID"
46+
```
4247

43-
```azurecli
44-
az group create --name myResourceGroup --location eastus
45-
```
48+
## Create a resource group
4649

47-
The following sample output resembles successful creation of the resource group:
50+
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.
4851

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-
```
52+
Create a resource group using the [`az group create`][az-group-create] command.
53+
54+
```azurecli-interactive
55+
az group create --name $MY_RESOURCE_GROUP_NAME --location $REGION
56+
```
57+
58+
Results:
59+
<!-- expected_similarity=0.3 -->
60+
```JSON
61+
{
62+
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myAKSResourceGroupxxxxxx",
63+
"location": "eastus",
64+
"managedBy": null,
65+
"name": "testResourceGroup",
66+
"properties": {
67+
"provisioningState": "Succeeded"
68+
},
69+
"tags": null,
70+
"type": "Microsoft.Resources/resourceGroups"
71+
}
72+
```
6173

6274
## Create an AKS cluster
6375

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-
```
76+
Create an AKS cluster using the [`az aks create`][az-aks-create] command. The following example creates a cluster with one node and enables a system-assigned managed identity.
7477

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

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)
82+
> [!NOTE]
83+
> 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)
7984
8085
## Connect to the cluster
8186

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.
87+
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.
8388

8489
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.
8590

86-
```azurecli
87-
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
91+
```azurecli-interactive
92+
az aks get-credentials --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_AKS_CLUSTER_NAME
8893
```
8994
9095
1. Verify the connection to your cluster using the [kubectl get][kubectl-get] command. This command returns a list of the cluster nodes.
9196
92-
```azurecli
97+
```azurecli-interactive
9398
kubectl get nodes
9499
```
95100
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-
103101
## Deploy the application
104102
105103
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,71 +347,73 @@ To deploy the application, you use a manifest file to create all the objects req
349347
350348
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.
351349
352-
1. Deploy the application using the [kubectl apply][kubectl-apply] command and specify the name of your YAML manifest.
350+
1. Deploy the application using the [`kubectl apply`][kubectl-apply] command and specify the name of your YAML manifest.
353351
354-
```azurecli
352+
```azurecli-interactive
355353
kubectl apply -f aks-store-quickstart.yaml
356354
```
357355
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-
371356
## Test the application
372357
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":::
358+
You can validate that the application is running by visiting the public IP address or the application URL.
359+
360+
Get the application URL using the following commands:
361+
362+
```azurecli-interactive
363+
runtime="5 minute"
364+
endtime=$(date -ud "$runtime" +%s)
365+
while [[ $(date -u +%s) -le $endtime ]]
366+
do
367+
STATUS=$(kubectl get pods -l app=store-front -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}')
368+
echo $STATUS
369+
if [ "$STATUS" == 'True' ]
370+
then
371+
export IP_ADDRESS=$(kubectl get service store-front --output 'jsonpath={..status.loadBalancer.ingress[0].ip}')
372+
echo "Service IP Address: $IP_ADDRESS"
373+
break
374+
else
375+
sleep 10
376+
fi
377+
done
378+
```
379+
380+
```azurecli-interactive
381+
curl $IP_ADDRESS
382+
```
383+
384+
Results:
385+
<!-- expected_similarity=0.3 -->
386+
```JSON
387+
<!doctype html>
388+
<html lang="">
389+
<head>
390+
<meta charset="utf-8">
391+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
392+
<meta name="viewport" content="width=device-width,initial-scale=1">
393+
<link rel="icon" href="/favicon.ico">
394+
<title>store-front</title>
395+
<script defer="defer" src="/js/chunk-vendors.df69ae47.js"></script>
396+
<script defer="defer" src="/js/app.7e8cfbb2.js"></script>
397+
<link href="/css/app.a5dc49f6.css" rel="stylesheet">
398+
</head>
399+
<body>
400+
<div id="app"></div>
401+
</body>
402+
</html>
403+
```
404+
405+
```JSON
406+
echo "You can now visit your web server at $IP_ADDRESS"
407+
```
408+
409+
:::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":::
406410

407411
## Delete the cluster
408412

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.
410-
411-
```azurecli
412-
az group delete --name myResourceGroup --yes --no-wait
413-
```
413+
If you don't plan on going through the [AKS tutorial][aks-tutorial], clean up unnecessary resources to avoid Azure charges. You can remove the resource group, container service, and all related resources using the [`az group delete`][az-group-delete] command.
414414

415-
> [!NOTE]
416-
> The AKS cluster was created with a system-assigned managed identity, which is the default identity option used in this quickstart. The platform manages this identity so you don't need to manually remove it.
415+
> [!NOTE]
416+
> The AKS cluster was created with a system-assigned managed identity, which is the default identity option used in this quickstart. The platform manages this identity so you don't need to manually remove it.
417417
418418
## Next steps
419419

@@ -441,4 +441,3 @@ To learn more about AKS and walk through a complete code-to-deployment example,
441441
[kubernetes-deployment]: ../concepts-clusters-workloads.md#deployments-and-yaml-manifests
442442
[aks-solution-guidance]: /azure/architecture/reference-architectures/containers/aks-start-here?toc=/azure/aks/toc.json&bc=/azure/aks/breadcrumb/toc.json
443443
[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)