Create Memorystore

Platform Admin Duration: 10 min | Persona: Platform Admin

In this section, you will create a Memorystore (redis) instance for the Online Boutique’s cartservice app to connect to. We will also create a second Memorystore (redis) with TLS enabled which will be leveraged in another section.

Initialize variables:

WORK_DIR=~/
source ${WORK_DIR}acm-workshop-variables.sh
echo "export REDIS_NAME=cart" >> ${WORK_DIR}acm-workshop-variables.sh
echo "export REDIS_TLS_NAME=cart-tls" >> ${WORK_DIR}acm-workshop-variables.sh
source ${WORK_DIR}acm-workshop-variables.sh

Create a folder dedicated for any resources related Online Boutique specifically:

mkdir ${WORK_DIR}$TENANT_PROJECT_DIR_NAME/$ONLINEBOUTIQUE_NAMESPACE

Define Memorystore (redis)

Define the Memorystore (redis) resource:

cat <<EOF > ${WORK_DIR}$TENANT_PROJECT_DIR_NAME/$ONLINEBOUTIQUE_NAMESPACE/memorystore.yaml
apiVersion: redis.cnrm.cloud.google.com/v1beta1
kind: RedisInstance
metadata:
  name: ${REDIS_NAME}
  namespace: ${TENANT_PROJECT_ID}
  annotations:
    config.kubernetes.io/depends-on: compute.cnrm.cloud.google.com/namespaces/${TENANT_PROJECT_ID}/ComputeNetwork/${GKE_NAME}
spec:
  authorizedNetworkRef:
    name: ${GKE_NAME}
  memorySizeGb: 1
  redisVersion: REDIS_6_X
  region: ${GKE_LOCATION}
  tier: BASIC
EOF

Define Memorystore (redis) with TLS enabled

Define the Memorystore (redis) resource with TLS enabled:

cat <<EOF > ${WORK_DIR}$TENANT_PROJECT_DIR_NAME/$ONLINEBOUTIQUE_NAMESPACE/memorystore-tls.yaml
apiVersion: redis.cnrm.cloud.google.com/v1beta1
kind: RedisInstance
metadata:
  name: ${REDIS_TLS_NAME}
  namespace: ${TENANT_PROJECT_ID}
  annotations:
    config.kubernetes.io/depends-on: compute.cnrm.cloud.google.com/namespaces/${TENANT_PROJECT_ID}/ComputeNetwork/${GKE_NAME}
spec:
  authorizedNetworkRef:
    name: ${GKE_NAME}
  memorySizeGb: 1
  redisVersion: REDIS_6_X
  region: ${GKE_LOCATION}
  tier: BASIC
  transitEncryptionMode: SERVER_AUTHENTICATION
EOF

Deploy Kubernetes manifests

cd ${WORK_DIR}$TENANT_PROJECT_DIR_NAME/
git add . && git commit -m "Memorystore (redis) instance" && git push origin main

Check deployments

graph TD; RedisInstance-.->Project RedisInstance-.->ComputeNetwork RedisInstance-.->Project RedisInstance-.->ComputeNetwork

List the Kubernetes resources managed by Config Sync in Config Controller for the Tenant project configs repository:

gcloud alpha anthos config sync repo describe \
    --project $HOST_PROJECT_ID \
    --managed-resources all \
    --sync-name repo-sync \
    --sync-namespace $TENANT_PROJECT_ID

Wait and re-run this command above until you see "status": "SYNCED". All the managed_resources listed should have STATUS: Current as well.

List the GitHub runs for the Tenant project configs repository:

cd ${WORK_DIR}$TENANT_PROJECT_DIR_NAME && gh run list

List the Google Cloud resources created:

gcloud redis instances list \
    --region=$GKE_LOCATION \
    --project=$TENANT_PROJECT_ID