Skip to content

Commit 948fdc7

Browse files
committed
Update how-to-attach-kubernetes-to-workspace.md
add sdk attach example
1 parent b7e5a33 commit 948fdc7

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

articles/machine-learning/how-to-attach-kubernetes-to-workspace.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ ms.custom: build-spring-2022, cliv2, sdkv2, event-tier1-build-2022
1414

1515
# Attach a Kubernetes cluster to Azure Machine Learning workspace
1616

17+
[!INCLUDE [dev v2](../../includes/machine-learning-dev-v2.md)]
18+
1719
Once Azure Machine Learning extension is deployed on AKS or Arc Kubernetes cluster, you can attach the Kubernetes cluster to Azure Machine Learning workspace and create compute targets for ML professionals to use.
1820

1921
## Prerequisites
@@ -66,9 +68,7 @@ We support two ways to attach a Kubernetes cluster to Azure Machine Learning wor
6668

6769
### [Azure CLI](#tab/cli)
6870

69-
[!INCLUDE [CLI v2](../../includes/machine-learning-CLI-v2.md)]
70-
71-
The following commands show how to attach an AKS and Azure Arc-enabled Kubernetes cluster, and use it as a compute target with managed identity enabled.
71+
The following CLI v2 commands show how to attach an AKS and Azure Arc-enabled Kubernetes cluster, and use it as a compute target with managed identity enabled.
7272

7373
**AKS cluster**
7474

@@ -114,6 +114,45 @@ Attaching a Kubernetes cluster makes it available to your workspace for training
114114
In the Kubernetes clusters tab, the initial state of your cluster is *Creating*. When the cluster is successfully attached, the state changes to *Succeeded*. Otherwise, the state changes to *Failed*.
115115

116116
:::image type="content" source="media/how-to-attach-arc-kubernetes/kubernetes-creating.png" alt-text="Screenshot of attached settings for configuration of Kubernetes cluster.":::
117+
118+
### [Azure SDK](#tab/sdk)
119+
120+
The following python SDK v2 code show how to attach an AKS and Azure Arc-enabled Kubernetes cluster, and use it as a compute target with managed identity enabled.
121+
122+
**AKS cluster**
123+
124+
```python
125+
from azure.ai.ml import load_compute
126+
127+
# for AKS cluster, the resource_id should be something like '/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.ContainerService/managedClusters/<CLUSTER_NAME>''
128+
compute_params = [
129+
{"name": "<COMPUTE_NAME>"},
130+
{"type": "kubernetes"},
131+
{
132+
"resource_id": "/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.ContainerService/managedClusters/<CLUSTER_NAME>"
133+
},
134+
]
135+
k8s_compute = load_compute(source=None, params_override=compute_params)
136+
ml_client.begin_create_or_update(k8s_compute).result()
137+
```
138+
139+
**Arc Kubernetes cluster**
140+
141+
```python
142+
from azure.ai.ml import load_compute
143+
144+
# for arc connected cluster, the resource_id should be something like '/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.ContainerService/connectedClusters/<CLUSTER_NAME>''
145+
compute_params = [
146+
{"name": "<COMPUTE_NAME>"},
147+
{"type": "kubernetes"},
148+
{
149+
"resource_id": "/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.ContainerService/connectedClusters/<CLUSTER_NAME>"
150+
},
151+
]
152+
k8s_compute = load_compute(source=None, params_override=compute_params)
153+
ml_client.begin_create_or_update(k8s_compute).result()
154+
155+
```
117156

118157
---
119158

0 commit comments

Comments
 (0)