Cloud / Google Compute Engine Interview questions
Last updated
1. What is Google Compute Engine?
Google Compute Engine (GCE) is Google Cloud's Infrastructure-as-a-Service offering. It lets you create and run virtual machines on Google's infrastructure, with full control over the operating system, software stack and networking.
You pick a machine type, a boot image and a disk, and the VM is running in under a minute. You pay per second (with a one-minute minimum) for the resources you use.
Typical uses are lift-and-shift of existing servers, custom databases, batch and HPC jobs, and any workload that needs OS-level access which managed services do not give you.
Take quiz
Software as a Service (SaaS)
Function as a Service only
Infrastructure as a Service (IaaS)
Database as a Service only
Automatic scale to zero by default
Built-in request-based billing
No need to pick any machine size
Full OS-level access and custom kernel-level software
2. What are the main components of a Compute Engine instance?
A VM is assembled from a few building blocks that you choose when you create it:
- Machine type - the vCPU and memory shape.
- Boot disk - a Persistent Disk or Hyperdisk created from an image.
- Network interface - attaches the VM to a VPC subnet, with an internal IP and optionally an external one.
- Service account - the identity the VM uses to call Google APIs.
- Metadata - key-value data such as startup scripts and SSH settings.
- Zone - the physical location where the VM runs.
Extras like additional disks, GPUs, labels and network tags are optional.
Take quiz
Boot image
Network tag
Service account
Machine type
The attached service account
The boot disk
The machine image family
The instance label
3. What are machine families in Compute Engine?
A machine family is a group of machine series tuned for a kind of workload. Within a family you pick a series (such as E2 or N2) and then a machine type.
| Family | Optimized for | Example series |
| General-purpose | Balanced price and performance, web and app servers | E2, N2, N2D, N4, C3, Tau T2D |
| Compute-optimized | High per-core performance, gaming, HPC | C2, C2D, H3 |
| Memory-optimized | Large in-memory databases, SAP HANA | M1, M2, M3 |
| Storage-optimized | High local SSD throughput and IOPS | Z3 |
| Accelerator-optimized | GPU workloads, ML training and inference | A2, A3, G2 |
Newer series get added regularly, so check the current list in the docs before you commit to one.
Take quiz
Memory-optimized
Compute-optimized
Storage-optimized
Shared-core
General-purpose
Accelerator-optimized
Memory-optimized
Compute-optimized
4. What are the types of machine types in Compute Engine?
Compute Engine offers three kinds of machine types:
- Predefined - fixed vCPU and memory ratios such as
n2-standard-4(4 vCPUs, 16 GB). Variants are standard, highmem and highcpu. - Custom - you choose the exact vCPU count and memory, within allowed ratios. Useful when no predefined size fits and you don't want to pay for unused memory.
- Shared-core - small E2 types like
e2-micro,e2-smallande2-mediumthat share a physical core and can burst briefly.
Custom machine types cost a bit more per unit than predefined ones, so they pay off only when the saved resources outweigh that premium.
Take quiz
When you want free-tier pricing
When no predefined size matches your vCPU and memory need
When you need a GPU
When you want automatic multi-zone replication
highcpu predefined types
Memory-optimized M-series types
Shared-core types like e2-micro
Sole-tenant node types
5. What is the difference between a region and a zone in Google Cloud?
A region is a geographic area, like us-east1. A zone is an isolated deployment area inside a region, like us-east1-b. Each region has three or more zones.
Compute Engine VMs and zonal disks live in a single zone. If that zone has an outage, resources there are affected, while other zones in the region keep running.
For high availability, spread instances across zones in a region (a regional managed instance group does this for you). For disaster recovery, spread across regions.
| Region | Zone |
Geographic area, e.g. europe-west1 |
Isolated location inside a region, e.g. europe-west1-c |
| Contains multiple zones | Treated as a single failure domain |
Take quiz
Use a larger machine type
Use a static external IP
Run instances in multiple zones of the same region
Add more network tags
asia-south1
asia
global-a
asia-south1-a
6. What are the types of disks available for Compute Engine VMs?
There are three storage options you can attach to a VM:
- Persistent Disk - network-attached block storage that survives VM deletion if you keep it. Types are
pd-standard(HDD),pd-balanced,pd-ssdandpd-extreme. - Hyperdisk - the newer block storage line where you can provision IOPS and throughput independently of size.
- Local SSD - physically attached, very fast, but ephemeral.
pd-balanced is the usual default for general workloads. Pick pd-ssd or Hyperdisk when latency or IOPS matter, and Local SSD for scratch data or caches.
Take quiz
pd-balanced
pd-standard
Hyperdisk Balanced
Local SSD
pd-balanced
pd-extreme
Local SSD
pd-archive
7. What is a Local SSD and when should you use it?
A Local SSD is a solid-state drive physically attached to the host server. Because it avoids the network, it delivers very high IOPS and low latency compared with Persistent Disk.
The catch is durability. Data survives a guest OS reboot and live migration, but it is lost when the VM is stopped, deleted or preempted. You also cannot snapshot a Local SSD.
Use it for caches, scratch space, temporary processing data and replicated databases where the application itself handles redundancy. Never keep your only copy of important data on it.
Take quiz
It is lost
It is moved automatically to a Persistent Disk
It is kept for 30 days
It is snapshotted automatically
The only copy of customer records
A cache or scratch area for temporary processing data
A boot disk that must be snapshotted daily
Long-term backup archives
8. What is an instance template in Compute Engine?
An instance template is a reusable definition of a VM: machine type, boot image, disks, network settings, service account, labels and metadata. It does not create anything by itself.
You use it to launch identical VMs or as the blueprint for a managed instance group. Templates are immutable. To change something, you create a new template and point the group at it.
Templates can be global or regional. Because they are just configuration, they are a key piece of repeatable, scripted deployments.
Take quiz
Yes, while instances are running
No, you create a new template instead
Yes, but only the machine type
Only through the serial console
Taking a backup of a disk
Opening firewall ports
Defining a VM configuration for creating identical instances or a MIG
Assigning a static IP
9. What is a managed instance group (MIG)?
A managed instance group runs a set of identical VMs created from one instance template and treats them as a single unit.
It gives you things you don't get with standalone VMs:
- Autoscaling based on load or schedule
- Autohealing, which recreates VMs that fail a health check
- Rolling updates to a new template
- Multi-zone deployment with a regional MIG
- Integration with load balancers
If an instance in a MIG is deleted or crashes, the group recreates it to match the target size.
Take quiz
It shuts the group down
It waits for an admin to recreate it
It recreates the VM to match the target size
It reduces the group's target size
They all share one boot disk
They all use the same internal IP
They always run in one zone
They are created from the same instance template
10. What are the pricing models available for Compute Engine?
You can pay for Compute Engine in a few ways, and most real deployments mix them.
| Model | How it works | Best for |
| On-demand | Per-second billing, no commitment | Unpredictable or short-lived workloads |
| Sustained use discounts | Automatic discount for running eligible VMs most of the month | Steady workloads, no action needed |
| Committed use discounts | 1 or 3 year commitment for a lower rate | Predictable baseline capacity |
| Spot VMs | Deep discount, but VMs can be preempted | Fault-tolerant batch jobs |
Sustained use discounts don't apply to every series (E2, for example, doesn't get them), so check eligibility.
Take quiz
Spot VMs
Sustained use discounts
On-demand pricing
Committed use discounts
Sustained use discount on eligible series
Committed use discount
Spot discount
Free tier credit
11. What are Spot VMs in Compute Engine?
Spot VMs are spare Compute Engine capacity sold at a steep discount (often well over 50% off on-demand prices). The trade-off is that Google can reclaim them at any time when it needs the capacity.
When that happens, the VM gets a short preemption notice (about 30 seconds) and is then stopped or deleted, depending on the termination action you set. Spot VMs have no maximum runtime, unlike the older preemptible VMs, and they don't come with an availability SLA.
They are a good match for batch processing, CI jobs, rendering and stateless workers. They are a bad match for a single database server.
Take quiz
About 30 seconds
About 24 hours
None at all
About 10 minutes
A single primary database
A fault-tolerant batch job that can retry
A license server with no failover
A payment gateway with a strict SLA
12. How do you create a VM using the gcloud command line?
Use gcloud compute instances create and pass the VM name plus the options you care about. Anything you leave out falls back to a default.
gcloud compute instances create web-1 \ --zone=us-central1-a \ --machine-type=e2-medium \ --image-family=debian-12 \ --image-project=debian-cloud \ --boot-disk-size=20GB \ --tags=http-server
Run gcloud compute instances list to confirm it is running, and gcloud compute ssh web-1 --zone=us-central1-a to connect.
Take quiz
--boot-disk-size
--machine-type
--image-family
--tags
gcloud compute vms show
gcloud instances get
gcloud compute instances list
gcloud compute disks status
13. What are images in Compute Engine?
An image is a template of a boot disk's contents (OS plus anything installed) used to create new boot disks. There are three flavors:
- Public images - maintained by Google or partners, such as Debian, Ubuntu, Windows Server and Rocky Linux.
- Custom images - ones you build from your own disks, snapshots or other images.
- Image families - a named pointer that always resolves to the newest non-deprecated image in the family.
Using a family such as debian-12 means new VMs automatically get the latest patched image without you tracking version names.
Take quiz
The oldest image in the project
A single running VM
The latest non-deprecated image in that family
A snapshot schedule
Only from Google's public catalog
Only from Cloud Storage buckets of other users
It must be bought from Marketplace
Your own disk, snapshot or another image
14. What is a snapshot in Compute Engine?
A snapshot is a point-in-time backup of a Persistent Disk or Hyperdisk. The first snapshot copies all used blocks, and later ones store only the blocks that changed, so they are incremental.
Snapshots are stored in Cloud Storage-backed multi-regional or regional locations that you choose. You can restore one by creating a new disk from it, even in a different zone or project.
You can automate them with a snapshot schedule, set a retention period, and take them while the VM is running, though quiescing the filesystem first gives a cleaner backup.
Take quiz
As full copies every time
Only as metadata
Inside the VM's boot disk
Incrementally, only changed blocks
Yes
No, it must stay in the original zone
Only in the same region
Only after converting it to a Local SSD
15. What are startup scripts and how does the metadata server work?
Every VM can read key-value metadata from the metadata server at http://metadata.google.internal/computeMetadata/v1/. Requests must carry the header Metadata-Flavor: Google.
A startup script is stored as the startup-script metadata key (or startup-script-url for a Cloud Storage file). The guest agent runs it every time the VM boots, which is handy for installing packages or pulling config.
curl -H "Metadata-Flavor: Google" \ http://metadata.google.internal/computeMetadata/v1/instance/name
A matching shutdown-script runs on a best-effort basis when the VM is being stopped.
Take quiz
Metadata-Flavor: Google
Authorization: Bearer root
X-GCE-Token: true
Content-Flavor: Compute
Only on the very first boot
Every time the VM boots
Only when a snapshot is restored
Only when triggered from Cloud Build
16. What is a service account on a Compute Engine VM?
A service account is the identity that software on the VM uses when calling Google Cloud APIs. Applications fetch short-lived tokens for it from the metadata server, so no key file needs to sit on disk.
By default, new VMs use the Compute Engine default service account, which often has broad permissions. It's better to create a dedicated service account with only the roles the workload needs.
Access also depends on access scopes on older setups, but the recommended approach is to grant IAM roles to the service account and keep scopes wide.
Take quiz
A key file in /etc
The metadata server
The firewall
The instance template name
Always use the default account with Editor role
Share one admin account across all projects
Use a dedicated service account with least-privilege roles
Embed JSON keys in the image
17. What are network tags in Compute Engine?
Network tags are text strings you attach to a VM. They are mainly used as targets or sources in VPC firewall rules and in custom routes.
For example, tag web servers with http-server and create an ingress rule that allows TCP 80 only for instances carrying that tag. New VMs with the same tag are covered automatically.
Tags are not the same as labels. Labels are for organizing and billing, and they have no effect on traffic.
Take quiz
Splitting the bill by team
Choosing the VM's zone
Selecting VMs as targets in firewall rules and routes
Encrypting the boot disk
The rule ignores it until restart
The rule needs a manual IP entry
Nothing, tags are cosmetic
The rule applies to the VM automatically
18. What types of IP addresses can a Compute Engine VM have?
Each VM gets an internal IP from its subnet's range, and can optionally get an external IP for internet access.
| Type | Behavior |
| Ephemeral internal | Assigned from the subnet, released when the VM is deleted |
| Static internal | Reserved so the address stays the same |
| Ephemeral external | Can change when the VM is stopped and started |
| Static external | Reserved, keeps the same public address until you release it |
Unused reserved static external addresses are billed, so release the ones you no longer need.
Take quiz
Static external IP
Reserved internal IP
Alias IP range
Ephemeral external IP
Reserved but unused addresses are billed
They are always free
They disable the VM firewall
They halve the VM's CPU quota
19. What is the difference between labels and network tags?
Both are metadata on a VM, but they serve different purposes.
| Labels | Network tags |
Key-value pairs, e.g. env=prod |
Plain strings, e.g. web |
| Used for organizing, filtering and billing reports | Used by firewall rules and routes |
| Visible in billing exports | Not visible in billing |
| Apply to many resource types | Apply to VM instances only |
Use labels to answer 'who owns this and what does it cost', and tags to control 'what can talk to what'.
Take quiz
Labels
Network tags
Startup scripts
Image families
Labels only
Network tags
Snapshot names
Machine types
20. Explain the lifecycle of a Compute Engine instance?
A VM moves through a set of states, and billing depends on which one it is in.
On creation it goes from PROVISIONING (resources reserved) to STAGING (booting) to RUNNING. From running you can stop it, suspend it or delete it. A stopped VM ends in TERMINATED, which still keeps its disks, while SUSPENDED keeps memory state too. REPAIRING appears if the platform is fixing a failed instance.
stateDiagram-v2 [*] --> PROVISIONING PROVISIONING --> STAGING STAGING --> RUNNING RUNNING --> STOPPING STOPPING --> TERMINATED TERMINATED --> PROVISIONING : start RUNNING --> SUSPENDING SUSPENDING --> SUSPENDED SUSPENDED --> RUNNING : resume RUNNING --> REPAIRING REPAIRING --> RUNNING TERMINATED --> [*] : delete
While a VM is TERMINATED you don't pay for vCPU and memory, but you still pay for attached disks and reserved IPs.
Take quiz
PROVISIONING
TERMINATED
STAGING
REPAIRING
vCPU and memory
Nothing at all
Attached disks and reserved static IPs
Only the network egress of the stopped VM
21. What is the difference between stopping, suspending, and resetting a VM?
They differ in what happens to memory and the guest OS.
| Action | Effect | Billing impact |
| Stop | Clean OS shutdown, memory is lost, disks kept | No vCPU/memory charge, disks still billed |
| Suspend | Memory and device state saved to storage, resumes where it left off | Pay for storage of the saved state and disks |
| Reset | Hard reboot, like pressing the reset button; memory cleared | VM stays RUNNING, billing continues |
Suspend is not available for every machine type (for example, those with GPUs or Local SSD), so check before relying on it.
Take quiz
Stop
Reset
Suspend
Delete
Saves memory to disk
Deletes the boot disk
Changes the machine type
Performs a hard reboot and clears memory
22. What is the difference between a snapshot and a machine image?
A snapshot protects one disk. A machine image protects a whole VM.
| Snapshot | Machine image |
| Single disk only | Config, metadata, permissions and data from all attached disks |
| Restored as a new disk | Used to create a fully configured new VM |
| Incremental, good for scheduled disk backups | Good for cloning or backing up an entire VM setup |
If you only need to bring back data, a snapshot is enough. If you need the VM back exactly as it was, with its machine type, labels and every disk, use a machine image.
Take quiz
Snapshot
Image family
Instance schedule
Machine image
A snapshot schedule
A sole-tenant node
A custom machine type
A startup script
23. What is the difference between zonal and regional Persistent Disks?
A zonal Persistent Disk lives in one zone and can attach only to VMs in that zone. A regional Persistent Disk synchronously replicates data between two zones in the same region.
That replication means that if one zone fails, you can force-attach the disk to a VM in the other zone and keep going. The price is higher cost and slightly higher write latency, because every write goes to both zones.
Regional disks are common for databases that need a simple failover story without application-level replication.
Take quiz
It replicates synchronously across two zones
It copies data nightly to Cloud Storage
It keeps a copy on a Local SSD
It replicates asynchronously across continents
They can't be attached to any VM
Higher cost and slightly higher write latency
They are read-only
They only work with Windows
24. Which is better for block storage, Persistent Disk or Hyperdisk, and why?
It depends on how much control over performance you need. With Persistent Disk, IOPS and throughput are tied largely to disk size and type, so you sometimes buy extra capacity just to get speed.
Hyperdisk lets you provision size, IOPS and throughput independently, so you pay only for the performance you need. Several newer machine series support Hyperdisk, and some of them support only Hyperdisk, so check compatibility.
For a simple web server, pd-balanced is fine and cheap. For a busy database with a known performance target, Hyperdisk is usually the better fit.
Take quiz
It is always free
IOPS and throughput can be provisioned independently of size
It is physically attached like Local SSD
It never needs a zone
A database with a strict, high IOPS target
A workload needing independent throughput tuning
A small web server with modest I/O needs
An HPC cluster with extreme storage needs
25. How does live migration work in Compute Engine?
When Google needs to patch or repair a host, live migration moves your running VM to another host without a reboot. Memory, CPU state and network connections are copied across while the VM keeps running, and the final cut-over pause is typically very short.
It's controlled by the onHostMaintenance setting. MIGRATE is the default for standard VMs. TERMINATE stops the VM instead, which is required for most GPU VMs and is how Spot VMs behave.
sequenceDiagram participant S as Source host participant D as Destination host S->>D: Copy memory pages while VM runs S->>D: Re-copy dirtied pages S->>D: Brief pause, send final state D-->>S: VM resumes on destination Note over D: VM keeps same IP and disks
Because the VM keeps its IP and disks, applications usually don't notice.
Take quiz
onHostMaintenance=TERMINATE
automaticRestart=false
onHostMaintenance=MIGRATE
preemptible=true
E2 general-purpose VMs
VMs with a service account
VMs with network tags
Spot VMs and most GPU VMs
26. How does autoscaling work in a managed instance group?
The autoscaler compares a signal with a target and adjusts the number of VMs between your minimum and maximum.
Common signals are average CPU utilization, load balancing serving capacity, Cloud Monitoring metrics and schedules. For example, with a CPU target of 60%, the group adds VMs when average CPU goes above that and removes them when it falls well below.
The initialization period tells the autoscaler how long a new VM takes to warm up, so it ignores data from VMs that aren't ready yet. Scale-in controls can also limit how fast VMs are removed to avoid flapping.
Take quiz
It sets the VM's boot disk size
It delays billing by one hour
It blocks scale-out entirely
It makes the autoscaler ignore metrics from VMs still warming up
Average CPU utilization
Number of network tags
Image family name
Snapshot count
27. What is autohealing in a managed instance group?
Autohealing replaces VMs whose application is unhealthy, not just VMs that are powered off. You attach an application-level health check (HTTP, HTTPS, TCP and so on) to the group.
If a VM fails the check for the configured number of consecutive probes, the MIG recreates it from the instance template. An initial delay setting stops the group from killing VMs that are still booting.
Autohealing health checks are separate from load balancer health checks. The first decides recreation, the second decides whether to send traffic.
Take quiz
Recreates it from the instance template
Resizes its disk
Moves it to another project
Only emails the admin
To increase CPU quota
To avoid recreating VMs that are still booting
To change the zone
To disable the health check
28. What is the difference between managed and unmanaged instance groups?
A managed instance group (MIG) is built from a template and the platform keeps it healthy and correctly sized. An unmanaged group is just a manual collection of existing, possibly different VMs.
| Managed (MIG) | Unmanaged |
| Identical VMs from a template | Mixed, hand-picked VMs |
| Autoscaling, autohealing, rolling updates | None of these |
| Can span zones (regional MIG) | Single zone only |
Unmanaged groups are mostly used to put existing, differently configured VMs behind a load balancer.
Take quiz
Unmanaged instance group
Managed instance group
Neither
Both equally
To get rolling updates
To get autohealing
To put existing, differently configured VMs behind a load balancer
To spread VMs across zones automatically
29. How do you choose between E2 and N2 machine types?
E2 is the cost-optimized general-purpose series. It runs on a mix of CPU platforms, offers dynamic resource management and gives the lowest price for light to moderate workloads. It doesn't get sustained use discounts.
N2 uses Intel Cascade Lake or newer processors, gives more consistent per-core performance, supports larger sizes and qualifies for sustained use discounts and a wider set of features.
Pick E2 for dev/test, small web apps and microservices where price matters most. Pick N2 when you need steadier performance, bigger shapes or features such as certain local SSD configurations.
Take quiz
M3
A3
E2
H3
A latency-sensitive workload needing consistent per-core speed
A very large memory-heavy database
An ML training job
A small dev/test web service where cost matters most
30. What are sole-tenant nodes and when would you choose them?
A sole-tenant node is a physical Compute Engine server dedicated to your project, so your VMs don't share the host with other customers.
You'd choose it for compliance rules that require physical isolation, for bring-your-own-license software that is licensed per physical core or socket, or to control VM placement using node affinity labels.
You pay for the whole node whether it's full or not, so it only makes economic sense when the isolation or licensing reason is real.
Take quiz
A free VM
A Local SSD with backups
A shared host with priority CPU
A physical server dedicated to your project
BYOL licensing tied to physical cores or sockets
Cheaper boot disks
Faster image downloads
Automatic autoscaling
31. What is a Shielded VM and what does it protect against?
Shielded VM hardens a VM against boot-level and kernel-level malware such as rootkits and bootkits. It combines three features:
- Secure Boot - only signed, trusted boot components can load.
- vTPM - a virtual trusted platform module used for measured boot.
- Integrity monitoring - compares boot measurements to a known-good baseline and reports differences in Cloud Monitoring.
It needs a Shielded VM-capable image, and it's on by default for many current public images.
Take quiz
Integrity monitoring
Live migration
Network tags
Snapshot schedules
Encrypts VM memory
Allows only signed, trusted boot components to load
Blocks all inbound traffic
Creates daily backups
32. What is OS Login and why should you use it?
OS Login ties Linux SSH access to IAM instead of SSH keys scattered in project or instance metadata. You grant roles/compute.osLogin for normal access or roles/compute.osAdminLogin for sudo.
The benefits are central control and clean offboarding. Remove the IAM role and access is gone everywhere, with no key hunting. You can also enforce two-step verification and get audit logs of logins.
gcloud compute instances add-metadata web-1 --metadata enable-oslogin=TRUE
Take quiz
roles/compute.viewer
roles/compute.osAdminLogin
roles/storage.admin
roles/compute.networkUser
Slow boot times
Disk fragmentation
Unmanaged SSH keys spread across metadata
Snapshot retention
33. How do you access a VM that has no external IP address?
Several options work without exposing the VM publicly:
- Identity-Aware Proxy (IAP) TCP forwarding -
gcloud compute ssh --tunnel-through-iapconnects over Google's network after an IAM check. - Bastion host - a hardened VM with an external IP that you hop through.
- VPN or Cloud Interconnect - reach the internal IP from on-premises.
For outbound access (updates, package installs) use Cloud NAT. For Google APIs only, enable Private Google Access on the subnet. IAP needs a firewall rule allowing the range 35.235.240.0/20 to your SSH port.
Take quiz
Cloud CDN
Cloud Armor
Identity-Aware Proxy TCP forwarding
Cloud Scheduler
Cloud DNS
Cloud Build
Shielded VM
Cloud NAT
34. What are committed use discounts and when should you choose them?
Committed use discounts (CUDs) trade a 1 or 3 year commitment for a lower price. There are two broad styles:
- Resource-based - commit to a quantity of vCPUs and memory in a region.
- Spend-based (flexible) - commit to an hourly spend amount that can apply across eligible machine families and regions.
Choose them for the steady baseline you know you'll run for a long time, and leave spikes to on-demand or autoscaling. You pay for the commitment even if you use less, so don't commit to peak usage.
Take quiz
Only what you use
Nothing until usage starts
Only the first month
The committed amount, even if usage drops
The steady baseline of long-running workloads
Only short experiments
Peak traffic for one day
Unused projects
35. How do firewall rules work for Compute Engine VMs?
VPC firewall rules are stateful and apply at the VM's network interface, not at the subnet edge. Each rule has a direction, priority (0 to 65535, lower wins), action, protocol and port, and a target.
Two implied rules always exist at the lowest priority: deny all ingress and allow all egress. So by default nothing gets in until you allow it.
Targets can be all instances, VMs with certain network tags, or VMs running as a particular service account. Service-account targeting is safer because tags can be set by anyone with edit rights on the VM.
| Implied rule | Action |
| Ingress | Deny all |
| Egress | Allow all |
Take quiz
The one with the lower priority number
The one created last
The one with the longer name
The one with a tag
Allowed from everywhere
Denied unless a rule allows it
Allowed from the same project only
Allowed on port 22 only
36. Why do Spot VMs get preempted and how do you handle it?
Spot VMs run on spare capacity. When Google needs that capacity back for on-demand customers, it preempts the VM after a short notice of about 30 seconds.
The application has to expect this. Practical handling looks like this:
- Run a
shutdown-scriptthat flushes state or uploads a checkpoint to Cloud Storage. - Poll the metadata key
instance/preemptedso the app can react sooner. - Put the VMs in a MIG so replacements are created when capacity returns.
- Design jobs to be restartable, with small units of work or regular checkpoints.
curl -H "Metadata-Flavor: Google" \ http://metadata.google.internal/computeMetadata/v1/instance/preempted
Spot VMs suit batch and stateless work. A job that cannot resume after a kill should not run on them.
Take quiz
The firewall log
The instance/preempted metadata key
The snapshot schedule
The image family
One long job with no saved state
A single VM holding the only copy of data
Small restartable tasks with periodic checkpoints
A job that needs 99.99% uptime
37. How do you troubleshoot a VM that is not reachable over SSH?
Work from the outside in, so you don't waste time on the guest OS when the cause is the network.
- Check the VM is
RUNNINGand has the IP you expect. - Verify a firewall rule allows TCP 22 from your source (or the IAP range 35.235.240.0/20 if you use IAP).
- Run a Connectivity Test in Network Intelligence Center to spot routing or rule blocks.
- Read the serial port output (
gcloud compute instances get-serial-port-output) for boot errors, a full disk or an sshd failure. - Enable the interactive serial console to log in and fix
sshdor permissions. - Check OS Login or metadata key settings if authentication is rejected.
If the disk is corrupted, attach the boot disk to a rescue VM and repair it there.
Take quiz
Cloud CDN logs
Billing export
Serial port output
Image family list
Cloud Scheduler
Artifact Registry
Cloud Build
Connectivity Tests
38. How can you optimize Compute Engine costs?
Start by finding waste, then match purchase options to the workload.
| Lever | What to do |
| Right-sizing | Apply the machine type recommendations from Recommender |
| Idle cleanup | Delete or stop idle VMs, unattached disks and unused static IPs |
| Scheduling | Use instance schedules to stop dev VMs outside working hours |
| Spot VMs | Move fault-tolerant batch jobs to Spot |
| Commitments | Cover the steady baseline with committed use discounts |
| Custom shapes | Use custom machine types or E2 for light workloads |
Labels plus a billing export to BigQuery make it easy to see which team or service is driving spend.
Take quiz
Shielded VM
Live migration
Image families
Instance schedules
Unattached Persistent Disks
Network tags
Labels
Metadata keys
39. How do you perform a rolling update in a managed instance group?
You create a new instance template and tell the MIG to move to it. The group replaces VMs gradually, so the service stays up.
Two settings control the pace. maxSurge is how many extra VMs may be created above the target size. maxUnavailable is how many may be down at once. In proactive mode the group actively replaces VMs, while opportunistic mode only updates VMs when they get recreated for other reasons.
gcloud compute instance-groups managed rolling-action start-update web-mig \ --version=template=web-v2 \ --max-surge=3 --max-unavailable=0 \ --region=us-central1
For a canary, list two versions and give the new one a target size of, say, 10%.
Take quiz
No reduction in serving capacity during the update
Skipping health checks
Deleting all VMs first
Changing the region
How many disks can be snapshotted
How many extra VMs may be created above target size
The maximum disk size
The number of firewall rules
40. What happens when you resize a Compute Engine boot disk?
You can only increase a disk's size. Shrinking isn't supported. The resize itself works while the VM runs, but the extra space is unusable until you grow the partition and filesystem inside the OS.
gcloud compute disks resize web-1 --size=100GB --zone=us-central1-a # then inside the VM (ext4 example) sudo growpart /dev/sda 1 sudo resize2fs /dev/sda1
Take a snapshot first as a safety net. To get a smaller disk, create a new smaller disk and copy the data over.
Take quiz
Yes, with a reboot
No, disks can only grow
Yes, using resize2fs alone
Only on Windows VMs
Recreate the instance template
Change the machine type
Extend the partition and filesystem
Delete the snapshot
41. How does VPC networking work with Compute Engine VMs?
A VPC network in Google Cloud is global, and its subnets are regional. A VM gets its internal IP from the subnet in its zone's region, and VMs in different regions of the same VPC reach each other over internal IPs with no extra routing.
Traffic decisions come from three things: routes (where packets go), firewall rules (what is allowed) and, for internet-bound traffic, an external IP or Cloud NAT. Internal DNS resolves VM names like web-1.us-central1-a.c.PROJECT.internal.
flowchart LR
VM1["VM in us-east1 subnet"] -->|internal IP| R["VPC routes"]
R --> FW{Firewall rules}
FW -->|allowed| VM2["VM in europe-west1 subnet"]
FW -->|to internet| NAT["External IP or Cloud NAT"]
Because the VPC is global, one network can span regions without VPN tunnels between them.
Take quiz
Zonal only
Regional only
Global, with regional subnets
Per VM
A larger boot disk
A snapshot
Live migration
Cloud NAT
42. When would you choose a regional MIG over a zonal MIG?
Choose a regional MIG when the service has to keep running if one zone fails. It spreads VMs across up to three zones in a region, and the autoscaler and load balancer work across all of them.
A zonal MIG stays in one zone. It is simpler, and it can make sense for dev environments, workloads tied to zonal resources such as a zonal disk or a specific GPU, or when cross-zone traffic cost matters.
A regional MIG needs enough quota and capacity in each zone, and your app must tolerate being served from several zones.
Take quiz
To get free egress
To avoid health checks
To use a larger boot disk
To survive the failure of a single zone
For a dev environment or a workload tied to a zonal resource
For a customer-facing service needing zone failure tolerance
For a service requiring multi-zone spreading
For a payment platform with 99.99% target
43. How do you design a highly available application on Compute Engine?
Remove single points of failure at each layer.
- Run VMs in a regional MIG across at least two zones.
- Put a global or regional load balancer in front, with health checks.
- Enable autohealing and autoscaling so failed VMs are replaced and capacity follows load.
- Keep state out of the VMs: use Cloud SQL (HA), Spanner or a regional Persistent Disk.
- Add a second region for disaster recovery if the target demands it.
flowchart TD U[Users] --> LB["Load balancer"] LB --> Z1["MIG instances zone A"] LB --> Z2["MIG instances zone B"] Z1 --> DB[(HA database)] Z2 --> DB
Test it by deleting a zone's VMs on purpose and checking that traffic keeps flowing.
Take quiz
A regional managed instance group
A single zonal VM
A Local SSD
A static external IP
On each VM's Local SSD only
In an HA managed database or regional storage, not on the VM
In the startup script
In network tags
44. How do you build immutable infrastructure with images and MIGs?
With immutable infrastructure you never patch a running VM. You bake a new image, then replace the VMs.
A typical flow is: build a golden image with Packer or an image builder pipeline, publish it into an image family, create a new instance template that references it, and roll the MIG to the new template. Rollback means switching back to the previous template.
flowchart LR A["Build image with Packer"] --> B["Publish to image family"] B --> C["New instance template"] C --> D["Rolling update on MIG"] D -->|problem| E["Roll back to old template"]
This avoids configuration drift and makes every VM identical and reproducible.
Take quiz
SSH into every VM and undo changes
Point the MIG back to the previous instance template
Resize the boot disks
Delete the VPC
Egress charges
Region quotas
Configuration drift between VMs
Billing labels
45. What are Confidential VMs and what trade-offs do they have?
Confidential VMs encrypt data in use. The VM's memory is encrypted with keys managed by the CPU hardware (AMD SEV, SEV-SNP or Intel TDX depending on the series) and the keys aren't accessible to Google.
This protects against a compromised host or privileged insider reading memory. It adds to the usual encryption at rest and in transit.
The trade-offs are a restricted list of supported machine series and regions, some feature limits (such as live migration support varying by type) and a small performance overhead. Use them for regulated or sensitive workloads.
Take quiz
Only data at rest
Only the VM name
Data in use, by encrypting VM memory
Only the network tags
They cannot use disks
They can't be in a VPC
They require a bastion host
Limited supported machine series and a small performance overhead
46. Which is better, Compute Engine or Cloud Run, and why?
Neither wins everywhere. It depends on how much control you need versus how much operations work you want to avoid.
| Compute Engine | Cloud Run |
| You manage OS, patching and scaling setup | Fully managed, containers only |
| Any software, kernel access, GPUs, stateful servers | Stateless request-driven containers |
| Pay while the VM exists | Pay for request time, scales to zero |
| Good for lift-and-shift and legacy apps | Good for new APIs and web services |
If the app is a stateless HTTP service in a container, Cloud Run usually saves effort and money. If it needs custom OS setup, persistent local state or specialized hardware, use Compute Engine.
Take quiz
A zonal MIG
A sole-tenant node
A Local SSD
Cloud Run
A legacy app needing OS-level customization
A tiny stateless webhook handler
A simple container API
A request-driven function
47. How are GPUs used with Compute Engine VMs?
There are two models. On accelerator-optimized series such as A2, A3 and G2, GPUs come built into the machine type. On N1, you attach GPUs (like NVIDIA T4 or V100) to the VM yourself.
VMs with GPUs usually can't live migrate, so onHostMaintenance must be TERMINATE and the VM restarts around maintenance events. You also have to install the NVIDIA driver, or use a Deep Learning VM image that already has it.
gcloud compute instances create gpu-1 \ --zone=us-central1-a --machine-type=g2-standard-4 \ --maintenance-policy=TERMINATE
Check GPU quota per region first, since requests fail quickly when quota is zero.
Take quiz
TERMINATE
MIGRATE
AUTO_SCALE
PREEMPT_ONLY
A Local SSD
The NVIDIA driver
A sole-tenant node
A static IP
48. How do you secure Compute Engine VMs?
Security is layered, so combine several controls rather than relying on one.
- Identity - dedicated least-privilege service accounts, OS Login for SSH.
- Network - no external IPs where possible, tight firewall rules, IAP for admin access, Cloud NAT for outbound.
- Host hardening - Shielded VM, and Confidential VM for sensitive memory.
- Data - customer-managed encryption keys (CMEK) on disks when policy requires it.
- Patching - VM Manager patch management on a schedule.
- Governance - organization policies such as blocking external IPs or requiring Shielded VM.
Audit logs and Security Command Center findings help you spot drift from this baseline.
Take quiz
A network tag
An organization policy constraint
A label
A snapshot schedule
Live migration
Instance templates
VM Manager patch management
Cloud NAT
49. What is VM Manager and what does it provide?
VM Manager is a suite for managing OS-level operations across a fleet of VMs. It relies on the OS Config agent, which is preinstalled on many public images.
It offers three main capabilities:
- OS patch management - scan for missing updates and run scheduled patch jobs with maintenance windows.
- OS inventory - collect installed packages and OS details.
- OS configuration management - apply OS policies that keep packages, files and settings in a desired state.
It must be enabled per project and the VM's service account needs the right permissions.
Take quiz
The Ops Agent
The Metadata-Flavor agent
The OS Config agent
The Shielded agent
OS inventory only
Live migration
Machine images
OS patch management
50. How do you migrate on-premises VMs to Compute Engine?
Google's tool for this is Migrate to Virtual Machines (the successor to Migrate for Compute Engine). It replicates the source VM's disks to Google Cloud while the source keeps running.
- Set up a connection and a source (VMware, AWS, Azure and others).
- Add the VM and let it replicate continuously.
- Create a test clone to validate the app without touching production.
- Schedule the cutover: a final sync, stop the source, and start the VM in Compute Engine.
- Finalize and clean up replication resources.
flowchart LR A["On-prem VM"] --> B["Continuous replication"] B --> C["Test clone"] C --> D[Cutover] D --> E["VM runs on Compute Engine"]
Test clones keep the risk low, since you can rehearse as often as needed before the real cutover.