Bird
Raised Fist0
GCPcloud~5 mins

Machine types and families (E2, N2, C2) in GCP - Commands & Configuration

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
Introduction
Choosing the right machine type helps your cloud server run smoothly without wasting money. Different machine families offer different balances of power and cost for your tasks.
When you want a cost-effective server for general tasks like websites or small apps.
When you need a balanced machine for medium workloads like databases or business apps.
When you require high CPU power for heavy tasks like data analysis or video processing.
When you want to optimize your cloud costs by selecting the right machine family.
When you are setting up virtual machines in Google Cloud and must pick a machine type.
Config File - instance-template.yaml
instance-template.yaml
apiVersion: compute.googleapis.com/v1
kind: InstanceTemplate
metadata:
  name: example-instance-template
properties:
  machineType: e2-medium
  disks:
  - boot: true
    autoDelete: true
    initializeParams:
      sourceImage: projects/debian-cloud/global/images/family/debian-11
  networkInterfaces:
  - network: global/networks/default
    accessConfigs:
    - name: External NAT
      type: ONE_TO_ONE_NAT

This file defines a virtual machine template in Google Cloud.

machineType sets the machine family and size (e.g., e2-medium).

disks defines the boot disk and OS image.

networkInterfaces configures network access with an external IP.

Commands
This command creates a virtual machine named example-e2-instance using the E2 machine family with medium size. It uses the Debian 11 image in the us-central1-a zone.
Terminal
gcloud compute instances create example-e2-instance --machine-type=e2-medium --image-family=debian-11 --image-project=debian-cloud --zone=us-central1-a
Expected OutputExpected
Created [https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/instances/example-e2-instance]. NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS example-e2-instance us-central1-a e2-medium 10.128.0.2 34.68.123.45 RUNNING
--machine-type - Specifies the machine family and size
--image-family - Selects the OS image family
--zone - Sets the geographic location of the VM
This command creates a virtual machine named example-n2-instance using the N2 machine family with 4 vCPUs and standard memory. It is good for balanced workloads.
Terminal
gcloud compute instances create example-n2-instance --machine-type=n2-standard-4 --image-family=debian-11 --image-project=debian-cloud --zone=us-central1-a
Expected OutputExpected
Created [https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/instances/example-n2-instance]. NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS example-n2-instance us-central1-a n2-standard-4 10.128.0.3 34.68.123.46 RUNNING
--machine-type - Specifies the machine family and size
--image-family - Selects the OS image family
--zone - Sets the geographic location of the VM
This command creates a virtual machine named example-c2-instance using the C2 machine family with 8 vCPUs. It is designed for high CPU performance tasks.
Terminal
gcloud compute instances create example-c2-instance --machine-type=c2-standard-8 --image-family=debian-11 --image-project=debian-cloud --zone=us-central1-a
Expected OutputExpected
Created [https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/instances/example-c2-instance]. NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS example-c2-instance us-central1-a c2-standard-8 10.128.0.4 34.68.123.47 RUNNING
--machine-type - Specifies the machine family and size
--image-family - Selects the OS image family
--zone - Sets the geographic location of the VM
This command lists all the example instances created in the us-central1-a zone to verify their status and machine types.
Terminal
gcloud compute instances list --filter="name~'example-.*-instance'" --zones=us-central1-a
Expected OutputExpected
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS example-e2-instance us-central1-a e2-medium 10.128.0.2 34.68.123.45 RUNNING example-n2-instance us-central1-a n2-standard-4 10.128.0.3 34.68.123.46 RUNNING example-c2-instance us-central1-a c2-standard-8 10.128.0.4 34.68.123.47 RUNNING
--filter - Filters instances by name pattern
--zones - Limits the list to a specific zone
Key Concept

If you remember nothing else from this pattern, remember: choose the machine family that best fits your workload needs to balance cost and performance.

Common Mistakes
Using a machine type that is too large for the workload
This wastes money because you pay for unused CPU and memory.
Select a smaller machine type like E2 for light workloads and scale up only if needed.
Choosing a machine family without understanding its purpose
You might get poor performance or overspend if the machine family doesn't match your workload.
Learn the differences: E2 is cost-effective general use, N2 is balanced, C2 is high CPU power.
Not specifying the zone when creating instances
The instance might be created in an unexpected zone, causing latency or management issues.
Always specify the zone with --zone flag to control where your VM runs.
Summary
Use gcloud commands to create virtual machines with specific machine types from E2, N2, or C2 families.
E2 machines are good for cost-effective general workloads, N2 for balanced performance, and C2 for CPU-intensive tasks.
Verify your instances with gcloud compute instances list to check their status and machine types.

Practice

(1/5)
1. Which Google Cloud machine family is best suited for cost-effective general use workloads?
easy
A. E2 family
B. N2 family
C. C2 family
D. M1 family

Solution

  1. Step 1: Understand the purpose of each machine family

    The E2 family is designed for cost-effective general use, N2 balances power and memory, and C2 is optimized for CPU-heavy tasks.
  2. Step 2: Match the workload type to the machine family

    Since the question asks for cost-effective general use, E2 is the best fit.
  3. Final Answer:

    E2 family -> Option A
  4. Quick Check:

    Cost-effective general use = E2 [OK]
Hint: E2 means economical general use machines [OK]
Common Mistakes:
  • Confusing C2 as cost-effective instead of CPU-optimized
  • Choosing N2 for cost savings instead of balance
  • Selecting a non-existent machine family like M1
2. Which of the following is the correct way to specify a C2 machine type in a Google Cloud VM instance configuration?
easy
A. machineType: 'zones/us-central1-a/machineTypes/m1-standard-4'
B. machineType: 'zones/us-central1-a/machineTypes/e2-standard-4'
C. machineType: 'zones/us-central1-a/machineTypes/n2-standard-4'
D. machineType: 'zones/us-central1-a/machineTypes/c2-standard-4'

Solution

  1. Step 1: Identify the correct machine family prefix for C2

    C2 machine types start with 'c2-', so the machine type string must include 'c2-standard-4'.
  2. Step 2: Verify the full machineType format

    The format is 'zones/{zone}/machineTypes/{machineType}', so 'zones/us-central1-a/machineTypes/c2-standard-4' is correct.
  3. Final Answer:

    machineType: 'zones/us-central1-a/machineTypes/c2-standard-4' -> Option D
  4. Quick Check:

    C2 machine type string includes 'c2-' prefix [OK]
Hint: C2 machine types start with 'c2-' in the path [OK]
Common Mistakes:
  • Using 'e2-' or 'n2-' prefix for C2 machines
  • Incorrect zone or path format
  • Using a non-existent machine family like 'm1-'
3. You launch a VM with machine type n2-standard-8. Which statement best describes this VM's characteristics?
medium
A. It is optimized for CPU-heavy workloads with 8 vCPUs.
B. It balances CPU and memory with 8 vCPUs and moderate RAM.
C. It is a cost-effective VM with limited CPU power.
D. It is a high-memory VM with 8 vCPUs and extra RAM.

Solution

  1. Step 1: Understand the N2 machine family purpose

    N2 machines balance CPU power and memory, suitable for general workloads needing moderate resources.
  2. Step 2: Analyze the machine type suffix

    'standard-8' means 8 virtual CPUs with balanced memory, not specialized for CPU-only or high-memory.
  3. Final Answer:

    It balances CPU and memory with 8 vCPUs and moderate RAM. -> Option B
  4. Quick Check:

    N2 = balanced CPU and memory [OK]
Hint: N2 means balanced CPU and memory machines [OK]
Common Mistakes:
  • Confusing N2 with C2 which is CPU-optimized
  • Thinking N2 is cost-effective like E2
  • Assuming N2 is high-memory only
4. A user tries to create a VM with machine type c2-standard-16 but gets an error. Which is the most likely cause?
medium
A. The zone does not support C2 machine types with 16 vCPUs.
B. The machine type name is misspelled; it should be c2-standrd-16.
C. C2 machines cannot have more than 8 vCPUs.
D. The user must specify the machine type without the zone prefix.

Solution

  1. Step 1: Check machine type naming and limits

    'c2-standard-16' is a valid machine type with 16 vCPUs; spelling is correct and allowed size.
  2. Step 2: Consider zone availability

    Some zones do not support all machine types or sizes, so the error likely comes from zone limitations.
  3. Final Answer:

    The zone does not support C2 machine types with 16 vCPUs. -> Option A
  4. Quick Check:

    Zone support limits cause machine type errors [OK]
Hint: Check zone supports machine type size before creating VM [OK]
Common Mistakes:
  • Assuming spelling error when name is correct
  • Believing C2 max vCPUs is 8 (it's higher)
  • Ignoring zone prefix requirement in machineType
5. You need to run a CPU-intensive data processing job that requires maximum CPU power but moderate memory. Which machine type should you choose to optimize performance and cost?
hard
A. e2-standard-16
B. n2-highmem-16
C. c2-standard-16
D. e2-highcpu-16

Solution

  1. Step 1: Identify workload requirements

    The job is CPU-intensive needing maximum CPU power with moderate memory.
  2. Step 2: Match machine family to workload

    C2 family is optimized for CPU-heavy workloads, while E2 is cost-effective general use and N2-highmem is for memory-heavy tasks.
  3. Step 3: Choose the best machine type

    Among options, 'c2-standard-16' provides high CPU power with balanced memory, fitting the requirement best.
  4. Final Answer:

    c2-standard-16 -> Option C
  5. Quick Check:

    CPU-heavy job = C2 machines [OK]
Hint: Use C2 for CPU-heavy jobs, not E2 or N2-highmem [OK]
Common Mistakes:
  • Choosing E2 for CPU-heavy instead of cost-effective use
  • Picking N2-highmem which wastes cost on extra memory
  • Selecting E2-highcpu which is less powerful than C2