Back to Microservices Demo

README

terraform/README.md

3-demo-concise3.5 KB
Original Source
<!-- Copyright 2022 Google LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->

Use Terraform to deploy Online Boutique on a GKE cluster

This page walks you through the steps required to deploy the Online Boutique sample application on a Google Kubernetes Engine (GKE) cluster using Terraform.

Prerequisites

  1. Create a new project or use an existing project on Google Cloud, and ensure billing is enabled on the project.

Deploy the sample application

  1. Clone the Github repository.

    bash
    git clone https://github.com/GoogleCloudPlatform/microservices-demo.git
    
  2. Move into the terraform/ directory which contains the Terraform installation scripts.

    bash
    cd microservices-demo/terraform
    
  3. Open the terraform.tfvars file and replace <project_id_here> with the GCP Project ID for the gcp_project_id variable.

  4. (Optional) If you want to provision a Google Cloud Memorystore (Redis) instance, you can change the value of memorystore = false to memorystore = true in this terraform.tfvars file.

  5. Initialize Terraform.

    bash
    terraform init
    
  6. See what resources will be created.

    bash
    terraform plan
    
  7. Create the resources and deploy the sample.

    bash
    terraform apply
    
    1. If there is a confirmation prompt, type yes and hit Enter/Return.

    Note: This step can take about 10 minutes. Do not interrupt the process.

Once the Terraform script has finished, you can locate the frontend's external IP address to access the sample application.

  • Option 1:

    bash
    kubectl get service frontend-external | awk '{print $4}'
    
  • Option 2: On Google Cloud Console, navigate to "Kubernetes Engine" and then "Services & Ingress" to locate the Endpoint associated with "frontend-external".

Clean up

To avoid incurring charges to your Google Cloud account for the resources used in this sample application, either delete the project that contains the resources, or keep the project and delete the individual resources.

To remove the individual resources created for by Terraform without deleting the project:

  1. Navigate to the terraform/ directory.

  2. Set deletion_protection to false for the google_container_cluster resource (GKE cluster).

    bash
    # Uncomment the line: "deletion_protection = false"
    sed -i "s/# deletion_protection/deletion_protection/g" main.tf
    
    # Re-apply the Terraform to update the state
    terraform apply
    
  3. Run the following command:

    bash
    terraform destroy
    
    1. If there is a confirmation prompt, type yes and hit Enter/Return.