Skip to content

Commit 6362ee9

Browse files
committed
Add azure vote sample for Redis
1 parent 480b78f commit 6362ee9

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

azure-votes-redis/README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Azure Service Operator sample for Azure Cache for Redis
2+
3+
This sample is a demonstration of how to use the Azure Service Operator (ASO) to provision an Azure Cache for Redis,
4+
and then deploy a web application that uses that managed Redis instance to store its data.
5+
6+
## Prerequisites
7+
8+
To deploy this demo application you'll need the following:
9+
10+
1. A Kubernetes cluster (at least version 1.21) [created and
11+
running](https://kubernetes.io/docs/tutorials/kubernetes-basics/create-cluster/),
12+
and [`kubectl`](https://kubernetes.io/docs/tasks/tools/#kubectl) configured to talk to it. (You can check your cluster
13+
version with `kubectl version`.) This could be a local [Kind cluster](https://kind.sigs.k8s.io/docs/user/quick-start/)
14+
or an [Azure Kubernetes Service
15+
cluster](https://docs.microsoft.com/en-us/azure/aks/tutorial-kubernetes-deploy-cluster)
16+
running in your subscription.
17+
18+
2. An Azure subscription to create Azure resources under.
19+
20+
## Set up Azure Service Operator
21+
22+
ASO lets you manage Azure resources using Kubernetes tools.
23+
The operator is installed in your cluster and propagates changes to resources there to the Azure Resource Manager.
24+
[Read more about how ASO works](https://github.com/azure/azure-service-operator#what-is-it)
25+
26+
Follow [these
27+
instructions](https://github.com/Azure/azure-service-operator/tree/master/v2#installation) to install the ASO v2 operator in your cluster.
28+
Part of this installs
29+
the [custom resource definitions](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) for some of the Azure Resources.
30+
31+
### Note:
32+
Only a few Custom Resource Definitions will be installed in your cluster when you follow the Azure Service Operator set up instructions. The CRDs required specifically to run this sample will be installed along with the sample.
33+
34+
35+
## Deploy the application and Azure resources
36+
37+
The YAML documents in [azure-vote-managed-redis.yaml](azure-vote-managed-redis.yaml) create a number of things:
38+
39+
* A Kubernetes namespace named `azure-vote`,
40+
* An Azure resource group named `aso-redis-demo`,
41+
* An Azure Cache for Redis instance. Note that the container spec for redis.cache.azure.com instance is configured to retrieve two secrets that are produced by the Azure Cache for Redis instance - hostname and primaryKey. As described [here](https://azure.github.io/azure-service-operator/guide/secrets/#how-to-retrieve-secrets-created-by-azure), these secrets need to be mapped to our sample application and the container for our sample application will be blocked until these two secrets are created.
42+
* A deployment and service for the popular [AKS voting sample app](https://github.com/Azure-Samples/azure-voting-app-redis). We have updated the original container spec to introduce environment variables for the managed Redis hostname and access key.
43+
44+
Create them all by applying the file:
45+
```sh
46+
kubectl apply -f azure-vote-managed-redis.yaml
47+
```
48+
49+
The operator will start creating the resource group and Azure Cache for Redis instance in Azure.
50+
You can monitor their progress with:
51+
```sh
52+
watch kubectl get -n azure-vote resourcegroup,redis
53+
```
54+
You can also find the resource group in the [Azure portal](https://portal.azure.com) and watch the Azure Cache for Redis instance being created there.
55+
56+
### Note
57+
It could take a few minutes for the Azure Cache for Redis to be provisioned. In that time you might see some `ResourceNotFound` errors, or messages indicating that the secret, Azure Cache for Redis or the application deployment are not ready.
58+
*This is OK!*
59+
Once the Redis instance is created, secrets will be created and will unblock the sample application container creation. All errors should eventually resolve once the Redis instance is provisioned.
60+
61+
## Test the application
62+
When the application runs, a Kubernetes service exposes the application front end to the internet. This process can take a few minutes to complete.
63+
64+
```sh
65+
kubectl get service azure-vote-front
66+
```
67+
68+
Copy the EXTERNAL-IP address from the output. To see the application in action, open a web browser to the external IP address of your service.
69+
70+
If you're interested in code for the application, it is available [here](https://github.com/Azure-Samples/azure-voting-app-redis).
71+
72+
## Clean up
73+
74+
When you're finished with the sample application you can clean all of the Kubernetes and Azure resources up by deleting the `cosmos-todo` namespace in your cluster.
75+
```sh
76+
kubectl delete namespace cosmos-todo
77+
```
78+
79+
Kubernetes will delete the web application pod and the operator will delete the Azure resource group and all the Cosmos DB resources.
80+
(Deleting a Cosmos DB account can take several minutes.)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: azure-vote
5+
---
6+
apiVersion: resources.azure.com/v1api20200601
7+
kind: ResourceGroup
8+
metadata:
9+
name: aso-redis-demo
10+
namespace: azure-vote
11+
spec:
12+
location: westcentralus
13+
---
14+
apiVersion: cache.azure.com/v1api20201201
15+
kind: Redis
16+
metadata:
17+
name: azure-vote-redis
18+
namespace: azure-vote
19+
spec:
20+
location: westcentralus
21+
owner:
22+
name: aso-redis-demo
23+
sku:
24+
family: C
25+
name: Basic
26+
capacity: 0
27+
enableNonSslPort: true
28+
minimumTlsVersion: "1.2"
29+
redisConfiguration:
30+
maxmemory-delta: "10"
31+
maxmemory-policy: allkeys-lru
32+
redisVersion: "6"
33+
operatorSpec:
34+
secrets:
35+
hostName:
36+
name: redis-hostname
37+
key: hostName
38+
primaryKey:
39+
name: redis-access-key
40+
key: primaryKey
41+
---
42+
apiVersion: apps/v1
43+
kind: Deployment
44+
metadata:
45+
name: azure-vote-front
46+
namespace: azure-vote
47+
spec:
48+
replicas: 1
49+
selector:
50+
matchLabels:
51+
app: azure-vote-front
52+
strategy:
53+
rollingUpdate:
54+
maxSurge: 1
55+
maxUnavailable: 1
56+
minReadySeconds: 5
57+
template:
58+
metadata:
59+
labels:
60+
app: azure-vote-front
61+
spec:
62+
nodeSelector:
63+
"kubernetes.io/os": linux
64+
containers:
65+
- name: azure-vote-front
66+
image: mcr.microsoft.com/azuredocs/azure-vote-front:v1
67+
ports:
68+
- containerPort: 80
69+
resources:
70+
requests:
71+
cpu: 250m
72+
limits:
73+
cpu: 500m
74+
env:
75+
- name: REDIS
76+
valueFrom:
77+
secretKeyRef:
78+
name: redis-hostname
79+
key: hostName
80+
optional: false
81+
- name: REDIS_PWD
82+
valueFrom:
83+
secretKeyRef:
84+
name: redis-access-key
85+
key: primaryKey
86+
optional: false
87+
---
88+
apiVersion: v1
89+
kind: Service
90+
metadata:
91+
name: azure-vote-front
92+
namespace: azure-vote
93+
spec:
94+
type: LoadBalancer
95+
ports:
96+
- port: 80
97+
selector:
98+
app: azure-vote-front
99+
100+

0 commit comments

Comments
 (0)