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.
Only Linux has been tested
- Google Cloud Account
- Redis Enterprise in Google Marketplace Account
- Some DNS Domain
- Use Google Domains if you don't have one
- A subdomain would also be fine:
foo.bar.com
- Configure your domain with Cloud DNS
- Project ID
- Region
git clone https://github.com/Redislabs-Solution-Architects/gcp-microservices-demo.git
pushd gcp-microservices-demo
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
terraform init
terraform apply --auto-approve
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"
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}"
gcloud container clusters get-credentials \
$(terraform output -raw gke_cluster_name) \
--region $(terraform output -raw region)
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.
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
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'"}]}]}}}}'
Visit your website and make sure everything is still in your cart
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"}]}]}}}}'
Now that everything is working and your items are still in your cart, you delete the OSS Redis deployment
kubectl delete deploy redis-cart
Congrats! You've completed the demo.
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 |
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. |