Google Cloud Compute Services Cheat Sheet

Google Cloud Compute Services

Google Cloud - Compute Services Options

Compute Engine

  • is a virtual machine (VM) hosted on Google’s infrastructure.
  • can run the public images for Google provided Linux and Windows Server as well as custom images created or imported from existing systems
  • availability policy determines how it behaves when there is a maintenance event
    • VM instance’s maintenance behavior onHostMaintenance, which determines whether the instance is live migrated MIGRATE (default) or stopped TERMINATE
    • Instance’s restart behavior automaticRestart  which determines whether the instance automatically restarts (default) if it crashes or gets stopped
  • Live migration helps keep the VM instances running even when a host system event, such as a software or hardware update, occurs
  • Preemptible VM is an instance that can be created and run at a much lower price than normal instances, however can be stopped at any time
  • Shielded VM offers verifiable integrity of the Compute Engine VM instances, to confirm the instances haven’t been compromised by boot- or kernel-level malware or rootkits.
  • Instance template is a resource used to create VM instances and managed instance groups (MIGs) with identical configuration
  • Instance group is a collection of virtual machine (VM) instances that can be managed as a single entity.
    • Managed instance groups (MIGs)
      • allows app creation with multiple identical VMs.
      • workloads can be made scalable and highly available by taking advantage of automated MIG services, including: autoscaling, autohealing, regional (multiple zone) deployment, and automatic updating
      • supports rolling update feature
      • works with load balancing services to distribute traffic across all of the instances in the group.
    • Unmanaged instance groups
      • allows load balance across a fleet of VMs that you manage yourself which may not be identical
  • Instance template are global, while instance groups are regional.
  • Machine image stores all the configuration, data, metadata and permissions from one or more disks required to create a VM instance
  • Sole-tenancy provides dedicated hosting only for the project’s VM and provides added layer of hardware isolation
  • deletionProtection prevents accidental VM deletion esp. for VMs running critical workloads and need to be protected
  • provides Sustained Discounts, Committed discounts, free tier etc in pricing

App Engine

  • App Engine helps build highly scalable applications on a fully managed serverless platform
  • Each Cloud project can contain only a single App Engine application
  • App Engine is regional, which means the infrastructure that runs the apps is located in a specific region, and Google manages it so that it is available redundantly across all of the zones within that region
  • App Engine application location or region cannot be changed once created
  • App engine allows traffic management to an application version by migrating or splitting traffic.
    • Traffic Splitting (Canary) – distributes a percentage of traffic to versions of the application.
    • Traffic Migration – smoothly switches request routing
  • Support Standard and Flexible environments
    • Standard environment
      • Application instances that run in a sandbox, using the runtime environment of a supported language only.
      • Sandbox restricts what the application can do
        • only allows the app to use a limited set of binary libraries
        • app cannot write to disk
        • limits the CPU and memory options available to the application
      • Sandbox does not support
        • SSH debugging
        • Background processes
        • Background threads (limited capability)
        • Using Cloud VPN
    • Flexible environment
      • Application instances run within Docker containers on Compute Engine virtual machines (VM).
      • As Flexible environment supports docker it can support custom runtime or source code written in other programming languages.
      • Allows selection of any Compute Engine machine type for instances so that the application has access to more memory and CPU.
  • min_idle_instances indicates the number of additional instances to be kept running and ready to serve traffic for this version.

GKE

Node Pool

GKE
commands
–num-nodes scale cluster –size is deprecated

Google Cloud App Engine

Google Cloud App Engine

  • App Engine helps build highly scalable applications on a fully managed serverless platform
  • App Engine provides PaaS and helps build and deploy apps quickly using popular languages or bring your own language runtimes and frameworks.
  • App Engine allows to scale the applications from zero to planet scale without having to manage infrastructure
  • Each Cloud project can contain only a single App Engine application
  • App Engine is regional, which means the infrastructure that runs the apps is located in a specific region, and Google manages it so that it is available redundantly across all of the zones within that region
  • App Engine application location or region cannot be changed once created
  • App Engine is well suited to applications that are designed using a microservice architecture
  • App Engine creates a default bucket in Cloud Storage for each app creation

Standard vs Flexible Environment

Refer blog post Standard vs Flexible Environment

App Engine Scaling

  • App Engine can automatically create and shut down instances as traffic fluctuates, or a number of instances can be specified to run regardless of the amount of traffic
  • App Engine supports the following scaling types, which controls how and when instances are created:
    • Basic (Standard Only)
      • creates instances when the application receives requests.
      • each instance will be shut down when the application becomes idle.
      • is ideal for work that is intermittent or driven by user activity.
    • Automatic
      • creates instances based on request rate, response latencies, and other application metrics.
      • thresholds can be specified for each of these metrics, as well as a minimum number instances to keep running at all times.
    • Manual
      • specifies the number of instances that continuously run regardless of the load level.
      • allows tasks such as complex initializations and applications that rely on the state of the memory over time.

Managing Traffic

App engine allows traffic management to an application version by migrating or splitting traffic.

Traffic Migration

  • Traffic migration smoothly switches request routing
  • Gradually moves traffic from the versions currently receiving traffic to one or more specified versions
  • Standard environment allows you to choose to route requests to the target version, either immediately or gradually.
  • Flexible environment only allows immediate traffic migration

Traffic Splitting

  • Traffic splitting distributes a percentage of traffic to versions of the application.
  • Allows canary deployments or conduct A/B testing between the versions and provides control over the pace when rolling out features
  • Traffic can be split to move 100% of traffic to a single version or to route percentages of traffic to multiple versions.
  • Traffic splitting is applied to URLs that do not explicitly target a version.
  • Traffic split is supported by using either an IP address or HTTP cookie. 
  • Default behaviour for splitting traffic is to do it by IP.
  • Setting up IP address traffic split is easier, but a cookie split is more precise
  • For traffic splitting, execute gcloud app deploy --no-promote to make a new version of the application available and then run gcloud app services set-traffic to start sending the new version traffic. Use --splits flag with two versions and weight

GCP Certification Exam Practice Questions

  • Questions are collected from Internet and the answers are marked as per my knowledge and understanding (which might differ with yours).
  • GCP services are updated everyday and both the answers and questions might be outdated soon, so research accordingly.
  • GCP exam questions are not updated to keep up the pace with GCP updates, so even if the underlying feature has changed the question might not be updated
  • Open to further feedback, discussion and correction.
  1. You have a website hosted on App Engine standard environment. You want 1% of your users to see a new test version of the website. You want to minimize complexity. What should you do?
    1. Deploy the new version in the same application and use the –migrate option.
    2. Deploy the new version in the same application and use the –splits option to give a weight of 99 to the current version and a weight of 1 to the new version.
    3. Create a new App Engine application in the same project. Deploy the new version in that application. Use the App Engine library to proxy 1% of the requests to the new version.
    4. Create a new App Engine application in the same project. Deploy the new version in that application. Configure your network load balancer to send 1% of the traffic to that new application.
  2. You have created an App engine application in the us-central region. However, you found out the network team has configured all the VPN connections in the asia-east2 region, which are not possible to move. How can you change the location efficiently?
    1. Change the region in app.yaml and redeploy
    2. From App Engine console, change the region of the application
    3. Change the region in application.xml within the application and redeploy
    4. Create a new project in the asia-east2 region and create app engine in the project

Google Cloud – App Engine Standard vs Flexible Environment

Google Cloud – App Engine Standard vs Flexible Environment

Application Execution

  • Standard environment
    • Application instances that run in a sandbox, using the runtime environment of a supported language only.
    • Sandbox restricts what the application can do
      • only allows the app to use a limited set of binary libraries
      • app cannot write to disk
      • limits the CPU and memory options available to the application
    • Sandbox does not support
      • SSH debugging
      • Background processes
      • Background threads (limited capability)
      • Using Cloud VPN
  • Flexible environment
    • Application instances run within Docker containers on Compute Engine virtual machines (VM).
    • As Flexible environment supports docker it can support custom runtime or source code written in other programming languages.
    • Allows selection of any Compute Engine machine type for instances so that the application has access to more memory and CPU.
  • Standard environment
    • application can accesses services such as Datastore via the built-in google.appengine APIs.
  • Flexible environment
    • Google APIs are no longer available.
    • GCP recommends using the Google Cloud client libraries, which make the application more portable.

Scaling

  • Standard Environment
    • Rapid scaling and Zero downscaling is possible, can scale from zero instances up to thousands very quickly.
    • uses a custom-designed autoscaling algorithm.
  • Flexible Environment
    • must have at least one instance running for each active version and can take longer to scale up in response to traffic.
    • uses the Compute Engine Autoscaler.

Health Checks

  • Standard environment
    • does not use health checks to determine whether or not to send traffic to an instance.
  • Flexible environment
    • Instances are health-checked, that will be used by the load balancer to determine whether or not to send traffic to an instance and whether or not it should be autohealed.

Traffic Migration

  • Standard environment
    • allows you to choose to route requests to the target version, either immediately or gradually.
  • Flexible environment
    • only allows immediate traffic migration

Single zone failures

  • Standard environment
    • applications are single-zoned and all instances of the application live in a single availability zone
    • In the event of a zone failure, the application starts new instances in a different zone in the same region and the load balancer routes traffic to the new instances.
    • Latency spike can be observed due to loading requests and also a Memcache flush.
  • Flexible environment
    • applications use Regional Managed Instance Groups with instances  distributed among multiple availability zones within a region.
    • In the event of a single zone failure, the load balancer stops routing traffic to that zone.
  • Standard Environment
    • Deployments are generally faster than deployments in flexible environment.
    • VM Instance comes up in seconds in case of auto scaling
  • Flexible Environment
    • Instance startup time in minutes rather than seconds when compared to standard environment
    • Deployment time in minutes rather than seconds when compared to standard environment

Google Cloud - App Engine Standard vs Flexible Environment

GCP Certification Exam Practice Questions

  • Questions are collected from Internet and the answers are marked as per my knowledge and understanding (which might differ with yours).
  • GCP services are updated everyday and both the answers and questions might be outdated soon, so research accordingly.
  • GCP exam questions are not updated to keep up the pace with GCP updates, so even if the underlying feature has changed the question might not be updated
  • Open to further feedback, discussion and correction.
  1. You’re writing a Python application and want your application to run in a sandboxed managed environment with the ability to scale up in seconds to account for huge spikes in demand. Which service should you host your application on?
    1. Compute Engine
    2. App Engine Flexible Environment
    3. Kubernetes Engine
    4. App Engine Standard Environment
  2. A Company is planning the migration of their web application to Google App Engine. However, they would still continue to use their on-premises database. How can they setup application?
    1. Setup the application using App Engine Standard environment with Cloud VPN to connect to database
    2. Setup the application using App Engine Flexible environment with Cloud VPN to connect to database
    3. Setup the application using App Engine Standard environment with Cloud Router to connect to database
    4. Setup the application using App Engine Flexible environment with Cloud Router to connect to database