From cccd783034e55db9caad083bbafa551ef9dc4c5c Mon Sep 17 00:00:00 2001 From: Reshma Abdul Rahim <61033581+Reshrahim@users.noreply.github.com> Date: Thu, 28 Sep 2023 08:34:36 -0400 Subject: [PATCH] Add AWS recipes to recipes tutorial (#656) * Add aws redis recipe content to quickstart * Address feedback * Update docs/content/getting-started/quickstarts/quickstart-recipe/index.md Co-authored-by: Aaron Crawfis * Merge edge * Fix codetab issue * Delete package-lock.json * Update content * Spcing * Fix command * Spcing * Delete recipes/.rad/rad.yaml * Delete recipes/app.bicep * Fix api version and resourcetype --------- Co-authored-by: Aaron Crawfis --- .../tutorials/tutorial-recipe/index.md | 150 ++++++++++++++---- .../tutorial-recipe/snippets/app-aws.bicep | 24 +++ 2 files changed, 139 insertions(+), 35 deletions(-) create mode 100644 docs/content/tutorials/tutorial-recipe/snippets/app-aws.bicep diff --git a/docs/content/tutorials/tutorial-recipe/index.md b/docs/content/tutorials/tutorial-recipe/index.md index c4286c64c..e0f57f481 100644 --- a/docs/content/tutorials/tutorial-recipe/index.md +++ b/docs/content/tutorials/tutorial-recipe/index.md @@ -1,6 +1,6 @@ --- type: docs -title: "How-To: Deploy Recipes in your Radius Application" +title: "Tutorial: Deploy Recipes in your Radius Application" linkTitle: "Recipes" description: "Learn how to use Radius Recipes within your application" weight: 500 @@ -9,17 +9,12 @@ categories: "How-To" tags : ["recipes"] --- -This how-to guide will teach you: +This tutorial will teach you the following about recipes * How to use “dev” Recipes in your Radius Environment to quickly run with containerized infrastructure. -* How to deploy your own Recipes in your Radius Environment to leverage cloud resources. +* How to deploy your own Recipes in your Radius Environment to leverage Azure/AWS resources. -## Prerequisites - -- Install the [rad CLI]({{< ref getting-started >}}) -- Setup a supported [Kubernetes cluster]({{< ref "guides/operations/kubernetes" >}}) - -## Overview +## Recipes overview [Recipes]({{< ref "guides/recipes/overview">}}) enable a separation of concerns between infrastructure teams and developers by automating infrastructure deployment. Developers define _what_ they need (_Redis, Mongo, etc._), and operators define _how_ it will be deployed (_Azure/AWS/Kubernetes infrastructure_). @@ -35,6 +30,11 @@ This application is a simple to-do list which stores and visualizes to-do items. Developers don't need to specify what cloud resources they're using in their application. Instead, they choose the portable Redis API which can be provided by any cloud provider (or a Docker container). When deployed, a Recipe will select what infrastructure to deploy and run. {{< /alert >}} +## Prerequisites + +- Install the [rad CLI]({{< ref getting-started >}}) +- Setup a supported [Kubernetes cluster]({{< ref "guides/operations/kubernetes" >}}) + ## Step 1: Initialize a Radius environment 1. Begin in a new directory for your application: @@ -57,18 +57,24 @@ Developers don't need to specify what cloud resources they're using in their app rad recipe list ``` - You should see a table of available Recipes (_with more to be added soon_): + You should see a table of available Recipes: ``` - NAME TYPE TEMPLATE - default Applications.Datastores/redisCaches radius.azurecr.io/recipes/dev/rediscaches:v0.21 + NAME TYPE TEMPLATE KIND TEMPLATE VERSION TEMPLATE + default Applications.Datastores/sqlDatabases bicep radius.azurecr.io/recipes/local-dev/sqldatabases:latest + default Applications.Messaging/rabbitMQQueues bicep radius.azurecr.io/recipes/local-dev/rabbitmqqueues:latest + default Applications.Dapr/pubSubBrokers bicep radius.azurecr.io/recipes/local-dev/pubsubbrokers:latest + default Applications.Dapr/secretStores bicep radius.azurecr.io/recipes/local-dev/secretstores:latest + default Applications.Dapr/stateStores bicep radius.azurecr.io/recipes/local-dev/statestores:latest + default Applications.Datastores/mongoDatabases bicep radius.azurecr.io/recipes/local-dev/mongodatabases:latest + default Applications.Datastores/redisCaches bicep radius.azurecr.io/recipes/local-dev/rediscaches:latest ``` - {{< alert title="💡 Dev Recipes" color="info" >}} - Dev environments are preloaded with [`dev` Recipes]({{< ref "guides/recipes/overview#use-community-dev-recipes" >}}), a set of Recipes that allow you to quickly get up and running with lightweight containerized infrastructure. In This how-to guide, the dev Redis Recipe deploys a lightweight Redis container into your Kubernetes cluster. +{{< alert title="💡 Dev Recipes" color="info" >}} +Dev environments are preloaded with [`dev` Recipes]({{< ref "guides/recipes/overview#use-community-dev-recipes" >}}), a set of Recipes that allow you to quickly get up and running with lightweight containerized infrastructure. In This how-to guide, the dev Redis Recipe deploys a lightweight Redis container into your Kubernetes cluster. - When a Recipe is named "default" it will be used by default when deploying resources when a Recipe is not specified. - {{< /alert >}} +When a Recipe is named "default" it will be used by default when deploying resources when a Recipe is not specified. +{{< /alert >}} ## Step 2: Define your application @@ -112,7 +118,7 @@ Note that no Recipe name is specified with 'db', so it will be using the default 2. List your Kubernetes Pods to see the infrastructure container deployed by the Recipe: ```bash - kubectl get pods -n default-webapp + kubectl get pods -n default-recipes ``` You will see your 'frontend' container, along with the Redis cache that was automatically created by the default dev Recipe: @@ -131,24 +137,25 @@ Note that no Recipe name is specified with 'db', so it will be using the default 4. Visit [`http://localhost:3000`](http://localhost:3000) in your browser. - You can now see both the environment variables of your container as well as interact with the `Todo App` and add/remove items in it as wanted: + You can now see both the environment variables of your container under Radius Connections as well as interact with the `Todo App` and add/remove items in it as wanted: screenshot of the todo application -## Step 4: Use Azure recipes in your application +## Step 4: Use Azure/AWS recipes in your application -This step requires an Azure subscription to deploy cloud resources, which will incur costs. You will need to add the [Azure cloud provider]({{< ref providers >}}) to your environment in order to deploy Azure resources and leverage Azure Recipes. +This step requires an Azure subscription or an AWS account to deploy cloud resources, which will incur costs. You will need to add the [Azure/AWS cloud provider]({{< ref providers >}}) to your environment in order to deploy Azure/AWS resources and leverage Azure Recipes. -{{< button text="Add a cloud provider" page="providers#configure-a-cloud-provider" newtab="true" >}} +{{< tabs Azure AWS >}} -{{< tabs Azure >}} {{% codetab %}} - 1. Delete your existing Redis cache, which we will redeploy with an Azure resource: ```bash rad resource delete rediscaches db ``` +1. Manually add the Azure cloud provider to your Radius environment + + Follow the steps [here]({{< ref "howto-azure-provider#manual-configuration" >}}) to add the Azure cloud provider to your existing environment. 2. Register the Recipe to your Radius Environment: @@ -186,9 +193,6 @@ This step requires an Azure subscription to deploy cloud resources, which will i db Applications.Datastores/redisCaches ``` -{{% /codetab %}} -{{< /tabs >}} - 5. Use the az CLI to see your newly deployed Azure Cache for Redis: ```bash @@ -202,21 +206,97 @@ This step requires an Azure subscription to deploy cloud resources, which will i "cache-goqoxgqkw2ogw" ] ``` +1. Port-forward the container to your machine with `rad resource expose`: + + ```bash + rad resource expose containers frontend --port 3000 + ``` + +1. Visit [`http://localhost:3000`](http://localhost:3000) in your browser. + + You can now see environment variables of your container under Radius Connections updated with the details of the Azure Cache for Redis and the Todo app now uses the Azure cache for Redis as the data store + + screenshot of the todo application + +{{% /codetab %}} + +{{% codetab %}} + +> *You can run this only on an EKS cluster. Make sure that the each of the Subnets in your EKS cluster Subnet Group are within the [list of supported MemoryDB availability zones](https://docs.aws.amazon.com/memorydb/latest/devguide/subnetgroups.html)* + +1. Delete your existing Redis cache, which we will redeploy with an AWS resource: + + ```bash + rad resource delete rediscaches db + ``` + +1. Manually add the AWS cloud provider to your Radius environment + + Follow the steps [here]({{< ref "howto-aws-provider#manual-configuration" >}}) to add the AWS cloud provider to your existing environment + +1. Register the Recipe to your Radius Environment: + + ```bash + rad recipe register aws --environment default --template-kind bicep --template-path radius.azurecr.io/recipes/aws/rediscaches:latest --resource-type Applications.Datastores/redisCaches --parameters eksClusterName= + ``` + > *Note: Passing the `eksClusterName` during the registration of the Recipe is a temporary additional step as Radius builds up AWS support.* -6. Port-forward the container to your machine with [`rad resource expose`]({{< ref rad_resource_expose>}}) +1. Update your db resource to use the `aws` Recipe, instead of the default Recipe: + + {{< rad file="snippets/app-aws.bicep" marker="//DB" embed=true >}} + + Update the recipe name to `aws` to use the Amazon MemoryDB for Redis. + +1. Deploy your application to your environment: + + ```bash + rad deploy ./app.bicep + ``` + + This operation may take some time, as the ‘aws’ Recipe is deploying an AWS MemoryDB for Redis resource in your AWS account. Once complete, you should see: + + ``` + Building ./app.bicep... + Deploying template './app.bicep' for application 'recipes' and environment 'default' from workspace 'default'... + + Deployment In Progress... + + Completed webapp Applications.Core/applications + Completed db Applications.Link/redisCaches + Completed frontend Applications.Core/containers + + Deployment Complete + + Resources: + webapp Applications.Core/applications + frontend Applications.Core/containers + db Applications.Link/redisCaches + ``` + +1. Port-forward the container to your machine with `rad resource expose`: + + ```bash + rad resource expose containers frontend --port 3000 + ``` + +1. Visit [`http://localhost:3000`](http://localhost:3000) in your browser. + + You can now see environment variables of your container under Radius Connections updated with the details of the Amazon Memory Db for Redis and the Todo app now uses the Amazon Memory Db for Redis as the data store + + screenshot of the todo application + +{{% /codetab %}} + +{{< /tabs >}} - ```bash - rad resource expose containers frontend -a webapp --port 3000 - ``` -7. Visit [localhost:3000](http://localhost:3000) in your browser again and interact with your application. ## Step 5: Cleanup your environment -You can use the rad CLI to [delete your environment]({{< ref rad_env_delete.md >}}) and all the Radius resources running on your cluster: +1. You can use the rad CLI to [delete your environment]({{< ref rad_env_delete.md >}}) and all the Radius resources running on your cluster: -```bash -rad env delete default --yes -``` + ```bash + rad env delete default --yes + ``` ## Next steps diff --git a/docs/content/tutorials/tutorial-recipe/snippets/app-aws.bicep b/docs/content/tutorials/tutorial-recipe/snippets/app-aws.bicep new file mode 100644 index 000000000..85faad934 --- /dev/null +++ b/docs/content/tutorials/tutorial-recipe/snippets/app-aws.bicep @@ -0,0 +1,24 @@ +import radius as radius + +@description('The ID of your Radius environment. Automatically injected by the rad CLI.') +param environment string + +@description('The ID of your Radius application. Automatically injected by the rad CLI.') +param application string + +@description('Name of the EKS cluster used for app deployment') +param eksClusterName string + +//DB +resource db 'Applications.Datastores/redisCaches@2023-10-01-preview' = { + name: 'db' + properties: { + environment: environment + application: application + recipe: { + // Name a specific recipe to use + name: 'aws' + } + } +} +//DB