GCloud

GCloud is a Command Line Interface that designs, builds and scales Google Cloud resources.

GCloud

  • Google Cloud CLI is an amazing resource to help automate the management and scaling of virtual machine instances within the Google eco-system.

GCloud init

  • Initial Command: gcloud auth list
    • Then click the button Authorize and the output should be:

      •       ACTIVE: *
              ACCOUNT: [email protected]
              To set the active account, run:
              $ gcloud config set account ACCOUNT
    • To grab current project ID, run gcloud config list project

      • OUTPUT:

        •     [core]
              project = {$project}

GCloud Compute

  • GCloud Compute Guide is still a work in progress; these are active notes from my current R&D.

    • shell gcloud compute --help
      • This will display all of the commands that will help you utilize the compute engine.
  • The are split into two major concepts, with GROUP and COMMAND.

    • According to Google, the compute command helps create, configure and manipulate the virtual machines within your pre-set project.
    • The SYNOPSIS is gcloud compute GROUP | COMMAND [GCLOUD_WIDE_FLAG ...]

GCloud Compute Load Balancer

  • Command to run 3 instances of nginx with an ingress load balancer.
    • Shell command for VM that is running nginx inside of a debian operating system.

      •        gcloud compute instances create www-server-1 \
                  --zone=us-west1-b \
                  --tags=network-lb-tag \
                  --machine-type=e2-medium \
                  --image-family=debian-11 \
                  --image-project=debian-cloud \
                  --metadata=startup-script=start_nginx.sh
        • start_nginx.sh ->

          •                   #!/bin/bash
                              apt-get update
                              apt-get install nginx -y
        • For switching from Nginx to Apache2, replace the nginx with apache2.

        • To check the status on ubuntu, run the sudo systemctl status nginx OR sudo systemctl status apache2.

      • Example of a Load Balance Template:

        • The shell below is an example of an instance template that creates the load balance backend template.

          •     gcloud compute instance-templates create lb-backend-template \
                --region=us-west1 \
                --network=default \
                --subnet=default \
                --tags=allow-health-check \
                --machine-type=e2-medium \
                --image-family=debian-11 \
                --image-project=debian-cloud \
                --metadata=startup-script=start_nginx_script.sh
                ```
            
        • Key concept is : Managed instance groups (MIGs)

          • Mage instance groups or MIGs enable you to operate applications on multiple identical / clone virtual machines, thus allowing your orchestration to become scalable and highly available. This is done by utilizing the components within the automated MIG services, which includes: autoscaling, autohealing, regional (multiple zone) deployment, and automatic updating.
      • Manage Instance Group for the load balancer:

        •     gcloud compute instance-groups managed create lb-backend-group \
              --template=lb-backend-template --size=2 --zone=us-west1-b 
        • Health Check:

        •     gcloud compute firewall-rules create fw-allow-health-check \
              --network=default \
              --action=allow \
              --direction=ingress \
              --source-ranges=130.211.0.0/22,35.191.0.0/16 \
              --target-tags=allow-health-check \
              --rules=tcp:80
              ```
          
        • Backend-Services fro gcloud compute

          • 
              gcloud compute backend-services create web-backend-service \
                  --protocol=HTTP \
                  --port-name=http \
                  --health-checks=http-basic-check \
                  --global
            
            • Add Instance Group as the Backend to the Backend Service:

              •       gcloud compute backend-services add-backend web-backend-service \
                  --instance-group=lb-backend-group \
                  --instance-group-zone=us-west1-b \
                  --global
            • Create a URL Map for routing the requests to the default backend services.

              •       gcloud compute url-maps create web-map-http \
                      --default-service web-backend-service
                      ```
                
              • Extra information regarding the URL Map: *** Note: URL map is a Google Cloud configuration resource used to route requests to backend services or backend buckets. For example, with an external HTTP(S) load balancer, you can use a single URL map to route requests to different destinations based on the rules configured in the URL map: Requests for https://example.com/video go to one backend service. Requests for https://example.com/audio go to a different backend service. Requests for https://example.com/images go to a Cloud Storage backend bucket. Requests for any other host and path combination go to a default backend service.

              • Create a target HTTP proxy to route requests:

                •         gcloud compute target-http-proxies create http-lb-proxy \
                          --url-map web-map-http
              • Global forwarding rule to route incoming requests to the proxy:

                •         gcloud compute forwarding-rules create http-content-rule \
                          --address=lb-ipv4-1\
                          --global \
                          --target-http-proxy=http-lb-proxy \
                          --ports=80

Google Forwarding Rules


Google Associate Cloud Engineer

  • The program requires the completion of 6 unique badges
    1. Badge 1 - Create and Manage Cloud Resources - 1
    2. Badge 2 - Perform Foundation Infrastructure Tasks in Google Cloud - 2
    3. Badge 3 - Set Up and Configure a Cloud Environment in Google Cloud - 3
    4. Badge 4 - Automating Infrastructure on Google Cloud with Terraform - 4
    5. Lab - GSP866 - 5
    6. Badge 5 - Deploy to Kubernetes in Google Cloud - 6