Explanation
To automatically recreate unhealthy VMs in a Managed Instance Group (MIG), you must configure autohealing with health checks. Here's why:
Autohealing with Health Checks:
- Autohealing is a feature of MIGs that automatically recreates instances that fail health checks
- You define health checks (HTTP, HTTPS, TCP, or SSL) that monitor the health of your instances
- When an instance fails the health check for a specified period, the MIG automatically recreates it
- This ensures your application remains available and healthy
Why other options are incorrect:
A) Firewall rules:
- Firewall rules control network traffic but don't automatically recreate unhealthy instances
- They can affect connectivity but not instance health management
C) Preemptible instances:
- Preemptible instances are low-cost, short-lived VMs that can be terminated by Google Cloud
- This is about cost optimization, not health monitoring and auto-recovery
D) Cloud Monitoring alerts:
- While Cloud Monitoring can alert you about unhealthy instances, it doesn't automatically recreate them
- You would need to set up additional automation (like Cloud Functions) to respond to alerts
Key Takeaway: Autohealing with health checks is the built-in MIG feature specifically designed to automatically replace unhealthy instances, making it the correct solution for this requirement.