Bird
Raised Fist0
GCPcloud~10 mins

Managed instance groups in GCP - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a managed instance group with a named instance template.

GCP
gcloud compute instance-groups managed create my-group --template=[1] --size=3 --zone=us-central1-a
Drag options to blanks, or click blank then click option'
Atemplate-instance
Binstance-template-1
Cmy-template
Ddefault-template
Attempts:
3 left
💡 Hint
Common Mistakes
Using a template name that does not exist
Omitting the --template flag
2fill in blank
medium

Complete the code to update the size of the managed instance group to 5.

GCP
gcloud compute instance-groups managed resize my-group --size=[1] --zone=us-central1-a
Drag options to blanks, or click blank then click option'
A3
B10
C5
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting size to a smaller number accidentally
Using a non-numeric value
3fill in blank
hard

Fix the error in the command to set the autohealing policy for the managed instance group.

GCP
gcloud compute instance-groups managed set-autohealing-policies my-group --health-check=[1] --initial-delay=300 --zone=us-central1-a
Drag options to blanks, or click blank then click option'
Aautoheal-check
Bmy-health-check
Ccheck-health
Dhealth-check-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using a health check name that does not exist
Misspelling the health check name
4fill in blank
hard

Fill both blanks to create a managed instance group with autoscaling enabled and set the max number of instances.

GCP
gcloud compute instance-groups managed create my-group --template=[1] --size=2 --zone=us-central1-a && gcloud compute instance-groups managed set-autoscaling my-group --max-num-replicas=[2] --zone=us-central1-a
Drag options to blanks, or click blank then click option'
Ainstance-template-2
Binstance-template-3
C5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using an invalid template name
Setting max replicas too low or too high
5fill in blank
hard

Fill all three blanks to update the instance template, resize the group, and set the autoscaling minimum size.

GCP
gcloud compute instance-groups managed rolling-action start-update my-group --version=template=[1] --zone=us-central1-a && gcloud compute instance-groups managed resize my-group --size=[2] --zone=us-central1-a && gcloud compute instance-groups managed set-autoscaling my-group --min-num-replicas=[3] --zone=us-central1-a
Drag options to blanks, or click blank then click option'
Ainstance-template-4
B4
C2
Dinstance-template-5
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up template names
Setting size or min replicas incorrectly

Practice

(1/5)
1. What is the main purpose of a Managed Instance Group (MIG) in Google Cloud?
easy
A. To create a single virtual machine with custom settings
B. To run multiple copies of the same virtual machine for reliability
C. To store large amounts of data in the cloud
D. To manage user access and permissions

Solution

  1. Step 1: Understand the role of Managed Instance Groups

    Managed Instance Groups run many copies of the same VM to keep applications reliable and available.
  2. Step 2: Compare options with this role

    Options describing storage, single VM creation, and permissions are other cloud services, not MIGs.
  3. Final Answer:

    To run multiple copies of the same virtual machine for reliability -> Option B
  4. Quick Check:

    MIGs = multiple VM copies for reliability [OK]
Hint: MIGs run many identical VMs to keep apps running [OK]
Common Mistakes:
  • Confusing MIGs with storage services
  • Thinking MIGs manage single VMs only
  • Mixing up MIGs with user permission management
2. Which command correctly creates a managed instance group named web-group with 3 instances using the instance template web-template?
easy
A. gcloud compute instance-groups managed create web-group --template=web-template --size=3
B. gcloud compute instance-groups create web-group --template web-template --count 3
C. gcloud compute managed-instances create web-group --template=web-template --size=3
D. gcloud compute instance-groups managed create web-group --template web-template --count=3

Solution

  1. Step 1: Identify correct gcloud syntax for managed instance group creation

    The correct command uses 'gcloud compute instance-groups managed create' with '--template' and '--size' flags.
  2. Step 2: Check each option for syntax correctness

    gcloud compute instance-groups managed create web-group --template=web-template --size=3 matches the correct syntax exactly. The other options have incorrect flags or command structure.
  3. Final Answer:

    gcloud compute instance-groups managed create web-group --template=web-template --size=3 -> Option A
  4. Quick Check:

    Correct command syntax = gcloud compute instance-groups managed create web-group --template=web-template --size=3 [OK]
Hint: Use '--template' and '--size' with 'instance-groups managed create' [OK]
Common Mistakes:
  • Using 'count' instead of 'size'
  • Omitting 'managed' keyword
  • Wrong command order or flags
3. Given this autoscaling policy for a managed instance group:
autoscaling:
  minNumReplicas: 2
  maxNumReplicas: 5
  cpuUtilization:
    targetUtilization: 0.6

What happens when CPU usage rises to 80%?
medium
A. The group stays at the current number of instances
B. The group scales down to 2 instances
C. The group scales up by adding more instances, up to 5
D. The group deletes all instances

Solution

  1. Step 1: Understand autoscaling triggers

    The target CPU utilization is 60%. When actual CPU usage is 80%, it is above the target.
  2. Step 2: Determine autoscaling behavior

    Since CPU usage is higher than target, autoscaler adds instances up to maxNumReplicas (5) to reduce load.
  3. Final Answer:

    The group scales up by adding more instances, up to 5 -> Option C
  4. Quick Check:

    CPU > target -> scale up [OK]
Hint: CPU above target means add instances [OK]
Common Mistakes:
  • Thinking it scales down when CPU is high
  • Assuming no change happens
  • Confusing min and max replica counts
4. You try to update a managed instance group with a new instance template but get an error. Which is the most likely cause?
medium
A. Autoscaling is disabled
B. You did not specify the rolling update policy
C. The managed instance group has zero instances
D. The instance template name is missing or incorrect

Solution

  1. Step 1: Identify common update errors

    Updating a MIG requires a valid instance template name; missing or wrong name causes errors.
  2. Step 2: Evaluate other options

    Rolling update policy is optional, zero instances or autoscaling off do not cause update errors.
  3. Final Answer:

    The instance template name is missing or incorrect -> Option D
  4. Quick Check:

    Invalid template name -> update error [OK]
Hint: Check instance template name carefully when updating MIG [OK]
Common Mistakes:
  • Assuming rolling update policy is mandatory
  • Ignoring template name correctness
  • Confusing autoscaling with update errors
5. You want to ensure zero downtime when updating a managed instance group with a new version of your app. Which strategy should you use?
hard
A. Perform a rolling update with a minimal number of instances unavailable at once
B. Delete all instances and recreate them with the new template immediately
C. Turn off autoscaling before updating and turn it back on after
D. Manually stop each instance, update it, then start it again

Solution

  1. Step 1: Understand zero downtime update methods

    Rolling updates replace instances gradually, keeping most instances running to avoid downtime.
  2. Step 2: Evaluate other options for downtime risk

    Deleting all instances or manual stop/start causes downtime; turning off autoscaling is unrelated.
  3. Final Answer:

    Perform a rolling update with a minimal number of instances unavailable at once -> Option A
  4. Quick Check:

    Rolling update = zero downtime [OK]
Hint: Use rolling updates to avoid downtime during MIG changes [OK]
Common Mistakes:
  • Deleting all instances at once
  • Manual updates causing downtime
  • Misunderstanding autoscaling role in updates