Skip to content

Redislabs-Solution-Architects/gcp-microservices-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis Google Cloud PRs Welcome Stability Experimental

Scaling Microservices Applications: Migration to Redis Enterprise on Google Cloud

This demo repo shows you how to deploy a fully functioning microservices application on Google Cloud using Open Source Redis and migrate the data to Redis Enterprise with minimal downtime.

Redis Enterprise for Online Boutique Mircoservices App

Prerequisites

Software to Install

Only Linux has been tested

Accounts Needed

Actions taken prior to demo

Information to Gather

Redis Enterprise in Google Cloud Marketplace

Google Cloud

  • Project ID
  • Region

Deployment

Clone the Repo

git clone https://github.com/Redislabs-Solution-Architects/gcp-microservices-demo.git
pushd gcp-microservices-demo

Create your own terraform.tfvars

The following values will need to be modified by you.

cat <<EOF >terraform.tfvars
gcp_project_id = "my_project"
domain_name = "demo.gcp-redis.com"
email_address = "john.doe@ob.com"
redis_access_key = "********"
redis_secret_key = "********"
EOF

Initialize Terraform

terraform init

Deploy the stack

terraform apply --auto-approve

What success looks like

Apply complete! Resources: 12 added, 0 changed, 0 destroyed.

Outputs:

db_password = <sensitive>
db_private_endpoint = "redis-10402.internal.c22052.us-central1-1.gcp.cloud.rlrcp.com:10402"
gke_cluster_name = "gke-glau-online-boutique"
region = "us-central1"
website = "https://demo2.gcp-redis.com"

Store Redis Enterprise database information in environment variables for later use

export REDIS_DEST=`terraform output db_private_endpoint | tr -d '"'`
export REDIS_DEST_PASS=`terraform output db_password | tr -d '"'`
export REDIS_ENDPOINT="${REDIS_DEST},user=default,password=${REDIS_DEST_PASS}"

Target your environment to the GKE cluster

gcloud container clusters get-credentials \
$(terraform output -raw gke_cluster_name) \
--region $(terraform output -raw region)

Run the demo

Access the web frontend in a browser using the "website" outputed after your terraform apply. The web application is using the inbuilt OSS Redis container as the backing store for the shopping cart. Make sure you add some items to your cart in order to see that data migration works as well.

Migrate the shopping cart data from OSS Redis to Redis Enterpirse in Google Cloud Marketplace

Create a K8s secret for Redis Enterprise database connection

kubectl apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
  name: redis-creds
type: Opaque
stringData:
  REDIS_SOURCE: redis://redis-cart:6379
  REDIS_DEST: redis://${REDIS_DEST}
  REDIS_DEST_PASS: ${REDIS_DEST_PASS}
EOF

Run a K8s job to migrate data from OSS Redis to Redis Enterprise database (Should take about 15 seconds)

kubectl apply -f https://raw.githubusercontent.com/Redislabs-Solution-Architects/gcp-microservices-demo/main/util/redis-migrator-job.yaml

Patch the "Cart" deployment to point to the new Redis Database

Run a K8s patch command to update the cartservice deployment to point to the new Redis Enterprise Endpoint (Should take about 30 seconds)

kubectl patch deployment cartservice --patch '{"spec":{"template":{"spec":{"containers":[{"name":"server","env":[{"name":"REDIS_ADDR","value":"'$REDIS_ENDPOINT'"}]}]}}}}'

Validate everything is working...

Visit your website and make sure everything is still in your cart

Command to roll back if needed:

If you need to roll back for any reason, this patch command will point back to OSS

kubectl patch deployment cartservice --patch '{"spec":{"template":{"spec":{"containers":[{"name":"server","env":[{"name":"REDIS_ADDR","value":"redis-cart:6379"}]}]}}}}'

Delete local redis-cart based on OSS Redis

Now that everything is working and your items are still in your cart, you delete the OSS Redis deployment

kubectl delete deploy redis-cart

Done!

Congrats! You've completed the demo.

Terraform Module Documentation

Inputs

Name Description Type Default Required
gcp_project_id The project ID to deploy the cluter into string n/a yes
domain_name The domain name to use for DNS records string n/a yes
email_address The email address to use with Cert Manager string n/a yes
redis_secret_key The secret key for accessing Redis Enterprise Cloud API string n/a yes
redis_access_key The access key for accessing Redis Enterprise Cloud API string n/a yes
cluster_name The name of the GKE cluster string "boutique" no
gcp_region The region to deploy the cluster in string "us-central1" no
gke_node_count The number of nodes to deploy in the cluster number 1 no
gke_release_channel The gke release channel to deploy string "RAPID" no
gke_machine_type The type of machine to deploy string "c2-standard-4" no
redis_subscription_cidr The name of the Redis Enterprise Cloud Subscription deployment's CIDR string "192.168.0.0/24" no
cert_manager_version The version of cert manager to install string "v1.10.0" no
redis_db_type The type of Redis DB to be setup by default. Valid options are 'OSS' or 'Ent' string "OSS" no

Outputs

Name Description
gke_cluster_name The name of the GKE cluster
region The Region the GKE cluster is deployed
db_private_endpoint The Redis DB endpoint
db_password The Redis DB Password
website The domain the website will be hosted on.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages