Skip to content

Commit 6e46613

Browse files
committed
Merged in PM updates
1 parent 5505c83 commit 6e46613

File tree

1 file changed

+108
-120
lines changed

1 file changed

+108
-120
lines changed
Lines changed: 108 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
---
22
title: 'Tutorial: Get started connecting an AKS application to a cache'
33
description: In this tutorial, you learn how to connect your AKS-hosted application to an Azure Cache for Redis instance.
4-
5-
6-
7-
84
ms.topic: tutorial
9-
ms.date: 08/15/2023
5+
ms.date: 10/01/2024
106
#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.
117

128
---
@@ -19,6 +15,7 @@ In this tutorial, you adapt the [AKS sample voting application](https://github.c
1915

2016
- An Azure subscription. If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
2117
- 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+
- An user assigned managed identity that you want to use to connect to your Azure Cache for Redis instance.
2219

2320
> [!IMPORTANT]
2421
> This tutorial assumes that you are familiar with basic Kubernetes concepts like containers, pods and service.
@@ -30,17 +27,42 @@ In this tutorial, you adapt the [AKS sample voting application](https://github.c
3027
For this tutorial, use a Standard C1 cache.
3128
:::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":::
3229

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.":::
30+
1. Follow the steps through to create the cache.
3531

36-
1. Follow the steps through to create the cache.
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**.
3733

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.
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+
## Configure your AKS cluster
4039

41-
Creating the cache can take a few minutes. You can move to the next section while the process finishes.
40+
1. Follow these [steps](aks/workload-identity-deploy-cluster.md) to configure a workload identity for your AKS cluster. Complete the following steps:
4241

43-
## Install and connect to your AKS cluster
42+
- Enable OIDC issuer and workload identity
43+
- Skip the step to create user assigned managed identity if you have 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.
44+
- Create a Kubernetes Service account annotated with the client id of your user assigned managed identity
45+
- Create a federated identity credential for your AKS cluster.
46+
47+
## Configure your workload that connects to Azure Cache for Redis
48+
49+
Next, set up the AKS workload to connect to Azure Cache for Redis after you have configured the AKS cluster.
50+
51+
1. Download the code for the [sample app](https://github.com/Azure-Samples/azure-cache-redis-sample/connect-from-aks).
52+
53+
1. Build and push docker image to your Azure Container Registry using [az acr build](https://learn.microsoft.com/en-us/cli/azure/acr?view=azure-cli-latest#az-acr-build) command
54+
55+
```bash
56+
az acr build --image sample/connect-from-aks-sample:1.0 --registry yourcontainerregistry --file Dockerfile .
57+
```
58+
59+
1. Attach your container registry to your AKS cluster using following command:
60+
61+
```bash
62+
az aks update --name clustername --resource-group mygroup --attach-acr youracrname
63+
```
64+
65+
## Deploy your workload
4466

4567
In this section, you first install the Kubernetes CLI and then connect to an AKS cluster.
4668

@@ -70,134 +92,100 @@ kubectl get nodes
7092

7193
You should see similar output showing the list of your cluster nodes.
7294

73-
```output
95+
```bash
7496
NAME STATUS ROLES AGE VERSION
75-
aks-agentpool-21274953-vmss000001 Ready agent 1d v1.24.15
76-
aks-agentpool-21274953-vmss000003 Ready agent 1d v1.24.15
77-
aks-agentpool-21274953-vmss000006 Ready agent 1d v1.24.15
97+
aks-agentpool-21274953-vmss000001 Ready agent 1d v1.29.7
98+
aks-agentpool-21274953-vmss000003 Ready agent 1d v1.29.7
99+
aks-agentpool-21274953-vmss000006 Ready agent 1d v1.29.7
78100
```
79101

80-
## Update the voting application to use Azure Cache for Redis
81-
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.
102+
## Run your workload
83103

84-
Make the following changes to the deployment file before you save the file as _azure-vote-sample.yaml_.
104+
1. This is 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. Replace the value of CONNECTION_STRING, CACHE_NAME and USER_ASSIGNED_PRINCIPAL_ID environment variables that correspond with your cache and managed identity.
85105

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.
87-
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.
89-
90-
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.
91-
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_.
93-
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:
106+
```YAML
107+
apiVersion: v1
108+
kind: Pod
110109
metadata:
110+
name: entrademo-pod
111111
labels:
112-
app: azure-vote-front
112+
azure.workload.identity/use: "true" # Required. Only pods with this label can use workload identity.
113113
spec:
114-
nodeSelector:
115-
"kubernetes.io/os": linux
114+
serviceAccountName: workload-identity-sa
116115
containers:
117-
- name: azure-vote-front
118-
image: mcr.microsoft.com/azuredocs/azure-vote-front:v1
119-
ports:
120-
- containerPort: 80
116+
- name: entrademo-container
117+
image: youracr.azurecr.io/connect-from-aks-sample:1.0
118+
imagePullPolicy: Always
119+
command: ["dotnet", "ConnectFromAKS.dll"]
121120
resources:
122-
requests:
123-
cpu: 250m
124121
limits:
125-
cpu: 500m
122+
memory: "256Mi"
123+
cpu: "500m"
124+
requests:
125+
memory: "128Mi"
126+
cpu: "250m"
126127
env:
127-
- name: REDIS
128-
value: myrediscache.redis.cache.windows.net
129-
- name: REDIS_PWD
130-
value: myrediscacheaccesskey
131-
---
132-
apiVersion: v1
133-
kind: Service
134-
metadata:
135-
name: azure-vote-front
136-
spec:
137-
type: LoadBalancer
138-
ports:
139-
- port: 80
140-
selector:
141-
app: azure-vote-front
142-
```
143-
144-
## Deploy and test your application
145-
146-
Run the following command to deploy this application to your AKS cluster:
147-
148-
```bash
149-
kubectl apply -f azure-vote-sample.yaml
150-
```
151-
152-
You get a response indicating your deployment and service was created:
153-
154-
```output
155-
deployment.apps/azure-vote-front created
156-
service/azure-vote-front created
157-
```
158-
159-
To test the application, run the following command to check if the pod is running:
160-
161-
```bash
162-
kubectl get pods
163-
```
164-
165-
You see your pod running successfully like:
166-
167-
```output
168-
NAME READY STATUS RESTARTS AGE
169-
azure-vote-front-7dd44597dd-p4cnq 1/1 Running 0 68s
170-
```
171-
172-
Run the following command to get the endpoint for your application:
173-
174-
```bash
175-
kubectl get service azure-vote-front
176-
```
177-
178-
You might see that the EXTERNAL-IP has status `<pending>` for a few minutes. Keep retrying until the status is replaced by an IP address.
179-
180-
```output
181-
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
182-
azure-vote-front LoadBalancer 10.0.166.147 20.69.136.105 80:30390/TCP 90s
183-
```
184-
185-
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:
186-
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.":::
188-
189-
## Clean up your deployment
128+
- name: CONNECTION_OPTION
129+
value: "MANAGED_IDENTITY" #ACCESS_KEY
130+
- name: CONNECTION_STRING # Required when connecting with access key
131+
value: "your connection string"
132+
- name: CACHE_NAME
133+
value: "your cache name"
134+
restartPolicy: Never
135+
136+
```
137+
138+
1. Save this file as podspec.yaml and then apply it to your AKS cluster by running the folloWing command:
139+
140+
```bash
141+
kubectl apply -f podspec.yaml
142+
```
143+
144+
You get a response indicating your pod was created:
145+
146+
```bash
147+
pod/entrademo-pod created
148+
```
149+
150+
1. To test the application, run the following command to check if the pod is running:
151+
152+
```bash
153+
kubectl get pods
154+
```
155+
156+
You see your pod running successfully like:
157+
158+
```bash
159+
NAME READY STATUS RESTARTS AGE
160+
entrademo-pod 0/1 Completed 0 42s
161+
```
162+
163+
1. Because this is a console app, you need to check the logs of the pod to verify that it ran as expected using this command.
164+
165+
```bash
166+
kubectl logs entrademo-app
167+
```
168+
169+
You will see the following logs that indicates your pod has successfully connected to your Redis instance using user assigned managed identity
170+
171+
```bash
172+
Connecting with managed identity..
173+
Retrieved value from Redis: Hello, Redis!
174+
Success! Previous value: Hello, Redis!
175+
```
176+
177+
## Clean up your cluster
190178

191179
To clean up your cluster, run the following commands:
192180

193181
```bash
194-
kubectl delete deployment azure-vote-front
195-
kubectl delete service azure-vote-front
182+
kubectl delete pod entrademo-pod
196183
```
197184

198185
[!INCLUDE [cache-delete-resource-group](includes/cache-delete-resource-group.md)]
199186

200187
## Related content
201188

202189
- [Quickstart: Deploy an Azure Kubernetes Service (AKS) cluster using the Azure portal](/azure/aks/learn/quick-kubernetes-deploy-portal)
203-
- [AKS sample voting application](https://github.com/Azure-Samples/azure-voting-app-redis/tree/master)
190+
- [Quickstart: Deploy and configure workload identity on an Azure Kubernetes Service (AKS) cluster](/azure/aks/workload-identity-deploy-cluster)
191+
- [Azure Cache for Redis Entra ID Authentication](/azure/azure-cache-for-redis/cache-azure-active-directory-for-authentication)

0 commit comments

Comments
 (0)