|
| 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.) |
0 commit comments