Skip to content

Commit c92b98d

Browse files
committed
Initial
1 parent 4fbddc6 commit c92b98d

1 file changed

Lines changed: 251 additions & 0 deletions

File tree

scenarios/AksKaito/README.md

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
---
2+
title: Deploy an AI model on Azure Kubernetes Service (AKS) with the AI toolchain operator (preview)
3+
description: Learn how to enable the AI toolchain operator add-on on Azure Kubernetes Service (AKS) to simplify OSS AI model management and deployment.
4+
ms.topic: article
5+
ms.custom: azure-kubernetes-service, devx-track-azurecli
6+
ms.date: 02/28/2024
7+
author: schaffererin
8+
ms.author: schaffererin
9+
10+
---
11+
12+
# Deploy an AI model on Azure Kubernetes Service (AKS) with the AI toolchain operator (preview)
13+
14+
The AI toolchain operator (KAITO) is a managed add-on for AKS that simplifies the experience of running OSS AI models on your AKS clusters. The AI toolchain operator automatically provisions the necessary GPU nodes and sets up the associated inference server as an endpoint server to your AI models. Using this add-on reduces your onboarding time and enables you to focus on AI model usage and development rather than infrastructure setup.
15+
16+
This article shows you how to enable the AI toolchain operator add-on and deploy an AI model on AKS.
17+
18+
[!INCLUDE [preview features callout](~/reusable-content/ce-skilling/azure/includes/aks/includes/preview/preview-callout.md)]
19+
20+
## Before you begin
21+
22+
* This article assumes a basic understanding of Kubernetes concepts. For more information, see [Kubernetes core concepts for AKS](./concepts-clusters-workloads.md).
23+
* For ***all hosted model inference images*** and recommended infrastructure setup, see the [KAITO GitHub repository](https://github.com/Azure/kaito).
24+
* The AI toolchain operator add-on currently supports KAITO version **v0.1.0**, please make a note of this in considering your choice of model from the KAITO model repository.
25+
26+
## Prerequisites
27+
28+
* If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
29+
* If you have multiple Azure subscriptions, make sure you select the correct subscription in which the resources will be created and charged using the [az account set][az-account-set] command.
30+
31+
> [!NOTE]
32+
> The subscription you use must have GPU VM quota.
33+
34+
* Azure CLI version 2.47.0 or later installed and configured. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI](/cli/azure/install-azure-cli).
35+
* The Kubernetes command-line client, kubectl, installed and configured. For more information, see [Install kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/).
36+
* [Install the Azure CLI AKS preview extension](#install-the-azure-cli-preview-extension).
37+
* [Register the AI toolchain operator add-on feature flag](#register-the-ai-toolchain-operator-add-on-feature-flag).
38+
39+
### Install the Azure CLI preview extension
40+
41+
1. Install the Azure CLI preview extension using the [az extension add][az-extension-add] command.
42+
43+
```azurecli-interactive
44+
az extension add --name aks-preview
45+
```
46+
47+
2. Update the extension to make sure you have the latest version using the [az extension update][az-extension-update] command.
48+
49+
```azurecli-interactive
50+
az extension update --name aks-preview
51+
```
52+
53+
### Register the AI toolchain operator add-on feature flag
54+
55+
1. Register the AIToolchainOperatorPreview feature flag using the [az feature register][az-feature-register] command.
56+
57+
```azurecli-interactive
58+
az feature register --namespace "Microsoft.ContainerService" --name "AIToolchainOperatorPreview"
59+
```
60+
61+
It takes a few minutes for the registration to complete.
62+
63+
2. Verify the registration using the [az feature show][az-feature-show] command.
64+
65+
```azurecli-interactive
66+
az feature show --namespace "Microsoft.ContainerService" --name "AIToolchainOperatorPreview"
67+
```
68+
69+
### Export environment variables
70+
71+
* To simplify the configuration steps in this article, you can define environment variables using the following commands. Make sure to replace the placeholder values with your own.
72+
73+
```azurecli-interactive
74+
export AZURE_SUBSCRIPTION_ID="mySubscriptionID"
75+
export AZURE_RESOURCE_GROUP="myResourceGroup"
76+
export AZURE_LOCATION="myLocation"
77+
export CLUSTER_NAME="myClusterName"
78+
```
79+
80+
## Enable the AI toolchain operator add-on on an AKS cluster
81+
82+
The following sections describe how to create an AKS cluster with the AI toolchain operator add-on enabled and deploy a default hosted AI model.
83+
84+
### Create an AKS cluster with the AI toolchain operator add-on enabled
85+
86+
1. Create an Azure resource group using the [az group create][az-group-create] command.
87+
88+
```azurecli-interactive
89+
az group create --name ${AZURE_RESOURCE_GROUP} --location ${AZURE_LOCATION}
90+
```
91+
92+
2. Create an AKS cluster with the AI toolchain operator add-on enabled using the [az aks create][az-aks-create] command with the `--enable-ai-toolchain-operator` and `--enable-oidc-issuer` flags.
93+
94+
```azurecli-interactive
95+
az aks create --location ${AZURE_LOCATION} \
96+
--resource-group ${AZURE_RESOURCE_GROUP} \
97+
--name ${CLUSTER_NAME} \
98+
--enable-oidc-issuer \
99+
--enable-ai-toolchain-operator \
100+
--generate-ssh-keys
101+
```
102+
103+
> [!NOTE]
104+
> AKS creates a managed identity once you enable the AI toolchain operator add-on. The managed identity is used to create GPU node pools in the managed AKS cluster. Proper permissions need to be set for it manually following the steps introduced in the following sections.
105+
>
106+
> AI toolchain operator enablement requires the enablement of OIDC issuer.
107+
108+
3. On an existing AKS cluster, you can enable the AI toolchain operator add-on using the [az aks update][az-aks-update] command.
109+
110+
```azurecli-interactive
111+
az aks update --name ${CLUSTER_NAME} \
112+
--resource-group ${AZURE_RESOURCE_GROUP} \
113+
--enable-oidc-issuer \
114+
--enable-ai-toolchain-operator
115+
```
116+
117+
## Connect to your cluster
118+
119+
1. Configure `kubectl` to connect to your cluster using the [az aks get-credentials][az-aks-get-credentials] command.
120+
121+
```azurecli-interactive
122+
az aks get-credentials --resource-group ${AZURE_RESOURCE_GROUP} --name ${CLUSTER_NAME}
123+
```
124+
125+
2. Verify the connection to your cluster using the `kubectl get` command.
126+
127+
```azurecli-interactive
128+
kubectl get nodes
129+
```
130+
131+
## Export environment variables
132+
133+
* Export environment variables for the MC resource group, principal ID identity, and KAITO identity using the following commands:
134+
135+
```azurecli-interactive
136+
export MC_RESOURCE_GROUP=$(az aks show --resource-group ${AZURE_RESOURCE_GROUP} \
137+
--name ${CLUSTER_NAME} \
138+
--query nodeResourceGroup \
139+
-o tsv)
140+
export PRINCIPAL_ID=$(az identity show --name "ai-toolchain-operator-${CLUSTER_NAME}" \
141+
--resource-group "${MC_RESOURCE_GROUP}" \
142+
--query 'principalId' \
143+
-o tsv)
144+
export KAITO_IDENTITY_NAME="ai-toolchain-operator-${CLUSTER_NAME}"
145+
```
146+
147+
## Get the AKS OpenID Connect (OIDC) Issuer
148+
149+
* Get the AKS OIDC Issuer URL and export it as an environment variable:
150+
151+
```azurecli-interactive
152+
export AKS_OIDC_ISSUER=$(az aks show --resource-group "${AZURE_RESOURCE_GROUP}" \
153+
--name "${CLUSTER_NAME}" \
154+
--query "oidcIssuerProfile.issuerUrl" \
155+
-o tsv)
156+
```
157+
158+
## Create role assignment for the service principal
159+
160+
* Create a new role assignment for the service principal using the [az role assignment create][az-role-assignment-create] command.
161+
162+
```azurecli-interactive
163+
az role assignment create --role "Contributor" \
164+
--assignee "${PRINCIPAL_ID}" \
165+
--scope "/subscriptions/${AZURE_SUBSCRIPTION_ID}/resourcegroups/${AZURE_RESOURCE_GROUP}"
166+
```
167+
168+
## Establish a federated identity credential
169+
170+
* Create the federated identity credential between the managed identity, AKS OIDC issuer, and subject using the [az identity federated-credential create][az-identity-federated-credential-create] command.
171+
172+
```azurecli-interactive
173+
az identity federated-credential create --name "kaito-federated-identity" \
174+
--identity-name "${KAITO_IDENTITY_NAME}" \
175+
-g "${MC_RESOURCE_GROUP}" \
176+
--issuer "${AKS_OIDC_ISSUER}" \
177+
--subject system:serviceaccount:"kube-system:kaito-gpu-provisioner" \
178+
--audience api://AzureADTokenExchange
179+
```
180+
181+
## Verify that your deployment is running
182+
183+
1. Restart the KAITO GPU provisioner deployment on your pods using the `kubectl rollout restart` command:
184+
185+
```azurecli-interactive
186+
kubectl rollout restart deployment/kaito-gpu-provisioner -n kube-system
187+
```
188+
189+
2. Verify that the deployment is running using the `kubectl get` command:
190+
191+
```azurecli-interactive
192+
kubectl get deployment -n kube-system | grep kaito
193+
```
194+
195+
## Deploy a default hosted AI model
196+
197+
1. Deploy the Falcon 7B-instruct model from the KAITO model repository using the `kubectl apply` command.
198+
199+
```azurecli-interactive
200+
kubectl apply -f https://raw.githubusercontent.com/Azure/kaito/main/examples/inference/kaito_workspace_falcon_7b-instruct.yaml
201+
```
202+
203+
2. Track the live resource changes in your workspace using the `kubectl get` command.
204+
205+
```azurecli-interactive
206+
kubectl get workspace workspace-falcon-7b-instruct -w
207+
```
208+
209+
> [!NOTE]
210+
> As you track the live resource changes in your workspace, note that machine readiness can take up to 10 minutes, and workspace readiness up to 20 minutes.
211+
212+
3. Check your service and get the service IP address using the `kubectl get svc` command.
213+
214+
```azurecli-interactive
215+
export SERVICE_IP=$(kubectl get svc workspace-falcon-7b-instruct -o jsonpath='{.spec.clusterIP}')
216+
```
217+
218+
4. Run the Falcon 7B-instruct model with a sample input of your choice using the following `curl` command:
219+
220+
```azurecli-interactive
221+
kubectl run -it --rm --restart=Never curl --image=curlimages/curl -- curl -X POST http://$SERVICE_IP/chat -H "accept: application/json" -H "Content-Type: application/json" -d "{\"prompt\":\"YOUR QUESTION HERE\"}"
222+
```
223+
224+
## Clean up resources
225+
226+
If you no longer need these resources, you can delete them to avoid incurring extra Azure charges.
227+
228+
* Delete the resource group and its associated resources using the [az group delete][az-group-delete] command.
229+
230+
```azurecli-interactive
231+
az group delete --name "${AZURE_RESOURCE_GROUP}" --yes --no-wait
232+
```
233+
234+
## Next steps
235+
236+
For more inference model options, see the [KAITO GitHub repository](https://github.com/Azure/kaito).
237+
238+
<!-- LINKS -->
239+
[az-group-create]: /cli/azure/group#az_group_create
240+
[az-group-delete]: /cli/azure/group#az_group_delete
241+
[az-aks-create]: /cli/azure/aks#az_aks_create
242+
[az-aks-update]: /cli/azure/aks#az_aks_update
243+
[az-aks-get-credentials]: /cli/azure/aks#az_aks_get_credentials
244+
[az-role-assignment-create]: /cli/azure/role/assignment#az_role_assignment_create
245+
[az-identity-federated-credential-create]: /cli/azure/identity/federated-credential#az_identity_federated_credential_create
246+
[az-account-set]: /cli/azure/account#az_account_set
247+
[az-extension-add]: /cli/azure/extension#az_extension_add
248+
[az-extension-update]: /cli/azure/extension#az_extension_update
249+
[az-feature-register]: /cli/azure/feature#az_feature_register
250+
[az-feature-show]: /cli/azure/feature#az_feature_show
251+
[az-provider-register]: /cli/azure/provider#az_provider_register

0 commit comments

Comments
 (0)