0
0
GCPcloud~5 mins

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

Choose your learning style9 modes available
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.