You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: 'Tutorial: Get started connecting an AKS application to a cache'
3
3
description: In this tutorial, you learn how to connect your AKS-hosted application to an Azure Cache for Redis instance.
4
-
5
-
6
-
7
-
8
4
ms.topic: tutorial
9
-
ms.date: 08/15/2023
5
+
ms.date: 10/01/2024
10
6
#CustomerIntent: As a developer, I want to see how to use a Azure Cache for Redis instance with an AKS container so that I see how I can use my cache instance with a Kubernetes cluster.
11
7
12
8
---
@@ -19,6 +15,7 @@ In this tutorial, you adapt the [AKS sample voting application](https://github.c
19
15
20
16
- An Azure subscription. If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
21
17
- An Azure Kubernetes Service Cluster - For more information on creating a cluster, see [Quickstart: Deploy an Azure Kubernetes Service (AKS) cluster using the Azure portal](/azure/aks/learn/quick-kubernetes-deploy-portal).
18
+
- A user assigned managed identity that you want to use to connect to your Azure Cache for Redis instance.
22
19
23
20
> [!IMPORTANT]
24
21
> This tutorial assumes that you are familiar with basic Kubernetes concepts like containers, pods and service.
@@ -30,17 +27,46 @@ In this tutorial, you adapt the [AKS sample voting application](https://github.c
30
27
For this tutorial, use a Standard C1 cache.
31
28
:::image type="content" source="media/cache-tutorial-aks-get-started/cache-new-instance.png" alt-text="Screenshot of creating a Standard C1 cache in the Azure portal":::
32
29
33
-
1. On the **Advanced** tab, enable **Non-TLS port**.
34
-
:::image type="content" source="media/cache-tutorial-aks-get-started/cache-non-tls.png" alt-text="Screenshot of the Advanced tab with Non-TLS enabled during cache creation.":::
35
-
36
30
1. Follow the steps through to create the cache.
37
31
38
-
> [!IMPORTANT]
39
-
> This tutorial uses a non-TLS port for demonstration, but we highly recommend that you use a TLS port for anything in production.
32
+
1. Once your Redis cache instance is created, navigate to the **Authentication** tab. Select the user assigned managed identity you want to use to connect to your Redis cache instance, then select **Save**.
33
+
34
+
1. Alternatively, you can navigate to Data Access Configuration on the Resource menu to create a new Redis user with your user assigned managed identity to connect to your cache.
35
+
36
+
1. Take note of the user name for your Redis user from the portal. You use this user name with the AKS workload.
37
+
38
+
## Run sample locally
39
+
40
+
To run this sample locally, configure your user principal as a Redis User on your Redis instance. The code sample will use your user principal through (DefaultAzureCredential)[https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication/?tabs=command-line#use-defaultazurecredential-in-an-application] to connect to Redis instance.
41
+
42
+
## Configure your AKS cluster
40
43
41
-
Creating the cache can take a few minutes. You can move to the next section while the process finishes.
44
+
Follow these [steps](/azure/aks/workload-identity-deploy-cluster) to configure a workload identity for your AKS cluster. Complete the following steps:
42
45
43
-
## Install and connect to your AKS cluster
46
+
- Enable OIDC issuer and workload identity
47
+
- Skip the step to create user assigned managed identity if you already created your managed identity. If you create a new managed identity, ensure that you create a new Redis User for your managed identity and assign appropriate data access permissions.
48
+
- Create a Kubernetes Service account annotated with the client ID of your user assigned managed identity
49
+
- Create a federated identity credential for your AKS cluster.
50
+
51
+
## Configure your workload that connects to Azure Cache for Redis
52
+
53
+
Next, set up the AKS workload to connect to Azure Cache for Redis after you configure the AKS cluster.
54
+
55
+
1. Download the code for the [sample app](https://github.com/Azure-Samples/azure-cache-redis-sample/connect-from-aks).
56
+
57
+
1. Build and push docker image to your Azure Container Registry using [az acr build](/cli/azure/acr#az-acr-build) command.
58
+
59
+
```bash
60
+
az acr build --image sample/connect-from-aks-sample:1.0 --registry yourcontainerregistry --file Dockerfile .
61
+
```
62
+
63
+
1. Attach your container registry to your AKS cluster using following command:
64
+
65
+
```bash
66
+
az aks update --name clustername --resource-group mygroup --attach-acr youracrname
67
+
```
68
+
69
+
## Deploy your workload
44
70
45
71
In this section, you first install the Kubernetes CLI and then connect to an AKS cluster.
46
72
@@ -56,148 +82,116 @@ If you use Azure Cloud Shell, _kubectl_ is already installed, and you can skip t
56
82
57
83
### Connect to your AKS cluster
58
84
59
-
Use the portal to copy the resource group and cluster name for your AKS cluster. To configure _kubectl_ to connect to your AKS cluster, use the following command with your resource group and cluster name:
60
-
61
-
```bash
62
-
az aks get-credentials --resource-group myResourceGroup --name myClusterName
63
-
```
64
-
65
-
Verify that you're able to connect to your cluster by running the following command:
85
+
1. Use the portal to copy the resource group and cluster name for your AKS cluster. To configure _kubectl_ to connect to your AKS cluster, use the following command with your resource group and cluster name:
66
86
67
-
```bash
68
-
kubectl get nodes
69
-
```
70
-
71
-
You should see similar output showing the list of your cluster nodes.
## Update the voting application to use Azure Cache for Redis
87
+
```bash
88
+
az aks get-credentials --resource-group myResourceGroup --name myClusterName
89
+
```
81
90
82
-
Use the [.yml file](https://github.com/Azure-Samples/azure-voting-app-redis/blob/master/azure-vote-all-in-one-redis.yaml) in the sample for reference.
91
+
1. Verify that you're able to connect to your cluster by running the following command:
83
92
84
-
Make the following changes to the deployment file before you save the file as _azure-vote-sample.yaml_.
93
+
```bash
94
+
kubectl get nodes
95
+
```
85
96
86
-
1. Remove the deployment and service named `azure-vote-back`. This deployment is used to deploy a Redis container to your cluster that is not required when using Azure Cache for Redis.
97
+
You should see similar output showing the list of your cluster nodes.
87
98
88
-
2. Replace the value `REDIS` variable from "azure-vote-back" to the _hostname_ of the Azure Cache for Redis instance that you created earlier. This change indicates that your application should use Azure Cache for Redis instead of a Redis container.
3. Define variable named `REDIS_PWD`, and set the value to the _access key_ for the Azure Cache for Redis instance that you created earlier.
106
+
## Run your workload
91
107
92
-
After all the changes, the deployment file should look like following file with your _hostname_ and _access key_. Save your file as _azure-vote-sample.yaml_.
108
+
1. The following code describes the pod specification file that you use to run our workload. Take note that the pod has the label _azure.workloadidentity/use: "true"_ and is annotated with _serviceAccountName_ as required by AKS workload identity. When using access key authentication, replace the value of AUTHENTICATION_TYPE, REDIS_HOSTNAME and REDIS_ACCESSKEY environment variables.
93
109
94
-
```YAML
95
-
apiVersion: apps/v1
96
-
kind: Deployment
97
-
metadata:
98
-
name: azure-vote-front
99
-
spec:
100
-
replicas: 1
101
-
selector:
102
-
matchLabels:
103
-
app: azure-vote-front
104
-
strategy:
105
-
rollingUpdate:
106
-
maxSurge: 1
107
-
maxUnavailable: 1
108
-
minReadySeconds: 5
109
-
template:
110
+
```yml
111
+
apiVersion: v1
112
+
kind: Pod
110
113
metadata:
114
+
name: entrademo-pod
111
115
labels:
112
-
app: azure-vote-front
116
+
azure.workload.identity/use: "true"# Required. Only pods with this label can use workload identity.
Once the External-IP is available, open a web browser to the External-IP address of your service and you see the application running as follows:
175
+
You see the following logs that indicate your pod successfully connected to your Redis instance using user assigned managed identity
186
176
187
-
:::image type="content" source="media/cache-tutorial-aks-get-started/cache-web-voting-app.png" alt-text="Screenshot of the voting application running in a browser with buttons for cats, dogs, and reset.":::
177
+
```bash
178
+
Connecting with managed identity..
179
+
Retrieved value from Redis: Hello, Redis!
180
+
Success! Previous value: Hello, Redis!
181
+
```
188
182
189
-
## Clean up your deployment
183
+
## Clean up your cluster
190
184
191
185
To clean up your cluster, run the following commands:
Copy file name to clipboardExpand all lines: articles/governance/policy/samples/australia-ism.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Regulatory Compliance details for Australian Government ISM PROTECTED
3
3
description: Details of the Australian Government ISM PROTECTED Regulatory Compliance built-in initiative. Each control is mapped to one or more Azure Policy definitions that assist with assessment.
Copy file name to clipboardExpand all lines: articles/governance/policy/samples/azure-security-benchmark.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Regulatory Compliance details for Microsoft cloud security benchmark
3
3
description: Details of the Microsoft cloud security benchmark Regulatory Compliance built-in initiative. Each control is mapped to one or more Azure Policy definitions that assist with assessment.
Copy file name to clipboardExpand all lines: articles/governance/policy/samples/built-in-policies.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: List of built-in policy definitions
3
3
description: List built-in policy definitions for Azure Policy. Categories include Tags, Regulatory Compliance, Key Vault, Kubernetes, Azure Machine Configuration, and more.
Copy file name to clipboardExpand all lines: articles/governance/policy/samples/canada-federal-pbmm.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Regulatory Compliance details for Canada Federal PBMM
3
3
description: Details of the Canada Federal PBMM Regulatory Compliance built-in initiative. Each control is mapped to one or more Azure Policy definitions that assist with assessment.
Copy file name to clipboardExpand all lines: articles/governance/policy/samples/cis-azure-1-1-0.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Regulatory Compliance details for CIS Microsoft Azure Foundations Benchmark 1.1.0
3
3
description: Details of the CIS Microsoft Azure Foundations Benchmark 1.1.0 Regulatory Compliance built-in initiative. Each control is mapped to one or more Azure Policy definitions that assist with assessment.
Copy file name to clipboardExpand all lines: articles/governance/policy/samples/cis-azure-1-3-0.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Regulatory Compliance details for CIS Microsoft Azure Foundations Benchmark 1.3.0
3
3
description: Details of the CIS Microsoft Azure Foundations Benchmark 1.3.0 Regulatory Compliance built-in initiative. Each control is mapped to one or more Azure Policy definitions that assist with assessment.
Copy file name to clipboardExpand all lines: articles/governance/policy/samples/cis-azure-1-4-0.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Regulatory Compliance details for CIS Microsoft Azure Foundations Benchmark 1.4.0
3
3
description: Details of the CIS Microsoft Azure Foundations Benchmark 1.4.0 Regulatory Compliance built-in initiative. Each control is mapped to one or more Azure Policy definitions that assist with assessment.
0 commit comments