Skip to content

Commit c4a065d

Browse files
authored
Merge pull request #268877 from wchigit/aks-support
[service connector] AKS support
2 parents b98a111 + 9148711 commit c4a065d

13 files changed

+797
-0
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
---
2+
title: How Service Connector helps Azure Kubernetes Service (AKS) connect to other Azure services
3+
description: Learn how to use Service Connector in Azure Kubernetes Service (AKS).
4+
author: houk-ms
5+
ms.service: service-connector
6+
ms.topic: conceptual
7+
ms.date: 03/01/2024
8+
ms.author: honc
9+
---
10+
# How to use Service Connector in Azure Kubernetes Service (AKS)
11+
12+
Azure Kubernetes Service (AKS) is one of the compute services supported by Service Connector. This article aims to help you understand:
13+
14+
* What operations are made on the cluster when creating a service connection.
15+
* How to use the kubernetes resources Service Connector creates.
16+
* How to troubleshoot and view logs of Service Connector in an AKS cluster.
17+
18+
## Prerequisites
19+
20+
* This guide assumes that you already know the [basic concepts of Service Connector](concept-service-connector-internals.md).
21+
22+
## What operations Service Connector makes on the cluster
23+
24+
Depending on the different target services and authentication types selected when creating a service connection, Service Connector makes different operations on the AKS cluster. The following lists the possible operations made by Service Connector.
25+
26+
### Add the Service Connector kubernetes extension
27+
28+
A kubernetes extension named `sc-extension` is added to the cluster the first time a service connection is created. Later on, the extension helps create kubernetes resources in user's cluster, whenever a service connection request comes to Service Connector. You can find the extension in your AKS cluster in the Azure portal, in the Extensions + applications menu.
29+
30+
:::image type="content" source="./media/aks-tutorial/sc-extension.png" alt-text="Screenshot of the Azure portal, view AKS extension.":::
31+
32+
The extension is also where the cluster connections metadata are stored. Uninstalling the extension makes all the connections in the cluster unavailable. The extension operator is hosted in the cluster namespace `sc-system`.
33+
34+
### Create kubernetes resources
35+
36+
Service Connector creates some kubernetes resources to the namespace the user specified when creating a service connection. The kubernetes resources store the connection information, which is needed by the user's workload definitions or application code to talk to target services. Depending on different authentication types, different kubernetes resources are created. For the `Connection String` and `Service Principal` auth types, a kubernetes secret is created. For the `Workload Identity` auth type, a kubernetes service account is also created in addition to a kubernetes secret.
37+
38+
You can find the kubernetes resources created by Service Connector for each service connection on the Azure portal in your kubernetes resource, in the Service Connector menu.
39+
40+
:::image type="content" source="./media/aks-tutorial/kubernetes-resources.png" alt-text="Screenshot of the Azure portal, view Service Connector created kubernetes resources.":::
41+
42+
Deleting a service connection doesn't delete the associated Kubernetes resource. If necessary, remove your resource manually, using for example the kubectl delete command.
43+
44+
### Enable the `azureKeyvaultSecretsProvider` addon
45+
46+
If target service is Azure Key Vault and the Secret Store CSI Driver is enabled when creating a service connection, Service Connector enables the `azureKeyvaultSecretsProvider` add-on for the cluster.
47+
48+
:::image type="content" source="./media/aks-tutorial/keyvault-csi.png" alt-text="Screenshot of the Azure portal, enabling CSI driver for keyvault when creating a connection.":::
49+
50+
Follow the [Connect to Azure Key Vault using CSI driver tutorial](./tutorial-python-aks-keyvault-csi-driver.md)to set up a connection to Azure Key Vault using Secret Store CSI driver.
51+
52+
### Enable workload identity and OpenID Connect (OIDC) issuer
53+
54+
If the authentication type is `Workload Identity` when creating a service connection, Service Connector enables workload identity and OIDC issuer for the cluster.
55+
56+
:::image type="content" source="./media/aks-tutorial/workload-identity.png" alt-text="Screenshot of the Azure portal, using workload identity to create a connection.":::
57+
58+
When the authentication type is `Workload Identity`, a user-assigned managed identity is needed to create the federated identity credential. Learn more from [what are workload identities](/entra/workload-id/workload-identities-overview), or follow the [tutorial](./tutorial-python-aks-storage-workload-identity.md)to set up a connection to Azure Storage using workload identity.
59+
60+
## How to use the Service Connector created kubernetes resources
61+
62+
Different kubernetes resources are created when the target service type and authentication type are different. The following sections show how to use the Service Connector created kubernetes resources in your cluster workloads definition and application codes.
63+
64+
#### Kubernetes secret
65+
66+
A kubernetes secret is created when the authentication type is `Connection String` or `Service Principal`. Your cluster workload definition can reference the secret directly. The following snnipet is an example.
67+
68+
```yaml
69+
apiVersion: batch/v1
70+
kind: Job
71+
metadata:
72+
namespace: default
73+
name: sc-sample-job
74+
spec:
75+
template:
76+
spec:
77+
containers:
78+
- name: raw-linux
79+
image: alpine
80+
command: ['printenv']
81+
envFrom:
82+
- secretRef:
83+
name: <SecretCreatedByServiceConnector>
84+
restartPolicy: OnFailure
85+
86+
```
87+
88+
Then, your application codes can consume the connection string in the secret from environment variable. You can check the [sample code](./how-to-integrate-storage-blob.md) to learn more about the environment variable names and how to use them in your application codes to authenticate to different target services.
89+
90+
#### Kubernetes service account
91+
92+
Both a kubernetes service account and a secret are created when the authentication type is `Workload Identity`. Your cluster workload definition can reference the service account and secret to authenticate through workload identity. The following snipet provides an example.
93+
94+
```yaml
95+
apiVersion: batch/v1
96+
kind: Job
97+
metadata:
98+
namespace: default
99+
name: sc-sample-job
100+
labels:
101+
azure.workload.identity/use: "true"
102+
spec:
103+
template:
104+
spec:
105+
serviceAccountName: <ServiceAccountCreatedByServiceConnector>
106+
containers:
107+
- name: raw-linux
108+
image: alpine
109+
command: ['printenv']
110+
envFrom:
111+
- secretRef:
112+
name: <SecretCreatedByServiceConnector>
113+
restartPolicy: OnFailure
114+
```
115+
116+
You may check the tutorial to learn [how to connect to Azure Storage using workload identity](tutorial-python-aks-storage-workload-identity.md).
117+
118+
## How to troubleshoot and view logs
119+
120+
If an error happens and couldn't be mitigated by retrying when creating a service connection, the following methods can help gather more information for troubleshooting.
121+
122+
### Check Service Connector kubernetes extension
123+
124+
Service Connector kubernetes extension is built on top of [Azure Arc-enabled Kubernetes cluster extensions](../azure-arc/kubernetes/extensions.md). Use the following commands to investigate if there are any errors during the extension installation or updating.
125+
126+
1. Install the `k8s-extension` Azure CLI extension.
127+
128+
```azurecli
129+
az extension add --name k8s-extension
130+
```
131+
132+
1. Get the Service Connector extension status. Check the `statuses` property in the command output to see if there are any errors.
133+
134+
```azurecli
135+
az k8s-extension show \
136+
--resource-group MyClusterResourceGroup \
137+
--cluster-name MyCluster \
138+
--cluster-type managedClusters \
139+
--name sc-extension
140+
```
141+
142+
### Check kubernetes cluster logs
143+
144+
If there's an error during the extension installation, and the error message in the `statuses` property doesn't provide enough information about what happened, you can further check the kubernetes logs with the followings steps.
145+
146+
1. Connect to your AKS cluster.
147+
148+
```azurecli
149+
az aks get-credentials \
150+
--resource-group MyClusterResourceGroup \
151+
--name MyCluster
152+
```
153+
1. Service Connector extension is installed in the namespace `sc-system` through helm chart, check the namespace and the helm release by following commands.
154+
155+
- Check the namespace exists.
156+
157+
```Bash
158+
kubectl get ns
159+
```
160+
161+
- Check the helm release status.
162+
163+
```Bash
164+
helm list -n sc-system
165+
```
166+
1. During the extension installation or updating, a kubernetes job called `sc-job` creates the kubernetes resources for the service connection. The job execution failure usually causes the extension failure. Check the job status by running the following commands. If `sc-job` doesn't exist in `sc-system` namespace, it should have been executed successfully. This job is designed to be automatically deleted after successful execution.
167+
168+
- Check the job exists.
169+
170+
```Bash
171+
kubectl get job -n sc-system
172+
```
173+
174+
- Get the job status.
175+
176+
```Bash
177+
kubectl describe job/sc-job -n sc-system
178+
```
179+
180+
- View the job logs.
181+
182+
```Bash
183+
kubectl logs job/sc-job -n sc-system
184+
```
185+
186+
## Next steps
187+
188+
Learn how to integrate different target services and read about their configuration settings and authentication methods.
189+
190+
> [!div class="nextstepaction"]
191+
> [Learn about how to integrate storage blob](./how-to-integrate-storage-blob.md)
58.5 KB
Loading
126 KB
Loading
218 KB
Loading
151 KB
Loading
71.8 KB
Loading
117 KB
Loading
319 KB
Loading
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
title: Quickstart - Create a service connection in Azure Kubernetes Service (AKS) with the Azure CLI
3+
description: Quickstart showing how to create a service connection in Azure Kubernetes Service (AKS) with the Azure CLI
4+
author: houk-ms
5+
ms.author: honc
6+
ms.service: service-connector
7+
ms.topic: quickstart
8+
ms.date: 03/01/2024
9+
ms.devlang: azurecli
10+
ms.custom: devx-track-azurecli
11+
---
12+
# Quickstart: Create a service connection in AKS cluster with the Azure CLI
13+
14+
This quickstart shows you how to connect Azure Kubernetes Service (AKS) to other Cloud resources using Azure CLI and Service Connector. Service Connector lets you quickly connect compute services to cloud services, while managing your connection's authentication and networking settings.
15+
16+
[!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)]
17+
18+
[!INCLUDE [azure-cli-prepare-your-environment.md](~/reusable-content/azure-cli/azure-cli-prepare-your-environment.md)]
19+
20+
* This quickstart requires version 2.30.0 or higher of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
21+
* This quickstart assumes that you already have an AKS cluster. If you don't have one yet, [create an AKS cluster](../aks/learn/quick-kubernetes-deploy-cli.md).
22+
* This quickstart assumes that you already have an Azure Storage account. If you don't have one yet, [create an Azure Storage account](../storage/common/storage-account-create.md).
23+
24+
## Initial set-up
25+
26+
1. If you're using Service Connector for the first time, start by running the command [az provider register](/cli/azure/provider#az-provider-register) to register the Service Connector resource provider.
27+
28+
```azurecli
29+
az provider register -n Microsoft.ServiceLinker
30+
```
31+
32+
> [!TIP]
33+
> You can check if the resource provider has already been registered by running the command `az provider show -n "Microsoft.ServiceLinker" --query registrationState`. If the output is `Registered`, then Service Connector has already been registered.
34+
35+
1. Optionally, use the Azure CLI command to get a list of supported target services for AKS cluster.
36+
37+
```azurecli
38+
az aks connection list-support-types --output table
39+
```
40+
41+
## Create a service connection
42+
43+
### [Using an access key](#tab/Using-access-key)
44+
45+
Run the following Azure CLI command to create a service connection to an Azure Blob Storage with an access key, providing the following information.
46+
47+
```azurecli
48+
az aks connection create storage-blob --secret
49+
```
50+
51+
Provide the following information as prompted:
52+
53+
* **Source compute service resource group name:** the resource group name of the AKS cluster.
54+
* **AKS cluster name:** the name of your AKS cluster that connects to the target service.
55+
* **Target service resource group name:** the resource group name of the Blob Storage.
56+
* **Storage account name:** the account name of your Blob Storage.
57+
58+
> [!NOTE]
59+
> If you don't have a Blob Storage, you can run `az aks connection create storage-blob --new --secret` to provision a new one and directly get connected to your aks cluster.
60+
61+
### [Using a workload identity](#tab/Using-Managed-Identity)
62+
63+
> [!IMPORTANT]
64+
> Using Managed Identity requires you have the permission to [Azure AD role assignment](../active-directory/managed-identities-azure-resources/howto-assign-access-portal.md). If you don't have the permission, your connection creation will fail. You can ask your subscription owner for the permission or use an access key to create the connection.
65+
66+
Use the Azure CLI command to create a service connection to a Blob Storage with a workload identity, providing the following information:
67+
68+
* **Source compute service resource group name:** the resource group name of the AKS cluster.
69+
* **AKS cluster name:** the name of your AKS cluster that connects to the target service.
70+
* **Target service resource group name:** the resource group name of the Blob Storage.
71+
* **Storage account name:** the account name of your Blob Storage.
72+
* **User-assigned identity subscription ID:** the subscription ID of the user assigned identity that used to create workload identity
73+
* **User-assigned identity client ID:** the client ID of the user assigned identity used to create workload identity
74+
75+
```azurecli
76+
az aks connection create storage-blob \
77+
--workload-identity client-id="<your-user-assigned-identity-client-id>" subs-id="<your-user-assigned-identity-subscription-id>"
78+
```
79+
80+
> [!NOTE]
81+
> If you don't have a Blob Storage, you can run `az aks connection create storage-blob --new --workload-identity client-id="<your-user-assigned-identity-client-id>" subs-id="<your-user-assigned-identity-subscription-id>"` to provision a new one and get connected to your function app straightaway.
82+
83+
---
84+
85+
## View connections
86+
87+
Use the Azure CLI [az aks connection list](/cli/azure/functionapp/connection#az-functionapp-connection-list) command to list connections to your AKS Cluster, providing the following information:
88+
89+
* **Source compute service resource group name:** the resource group name of the AKS cluster.
90+
* **AKS cluster name:** the name of your AKS cluster that connects to the target service.
91+
92+
```azurecli
93+
az aks connection list \
94+
-g "<your-aks-cluster-resource-group>" \
95+
-n "<your-aks-cluster-name>" \
96+
--output table
97+
```
98+
99+
## Next steps
100+
101+
Go to the following tutorials to start connecting AKS cluster to Azure services with Service Connector.
102+
103+
> [!div class="nextstepaction"]
104+
> [Tutorial: Connect to Azure Key Vault using CSI driver](./tutorial-python-aks-keyvault-csi-driver.md)
105+
106+
> [!div class="nextstepaction"]
107+
> [Tutorial: Connect to Azure Storage using workload identity](./tutorial-python-aks-storage-workload-identity.md)

0 commit comments

Comments
 (0)