Cloud Monitoring – Implement Uptime Checks for Instances Without External IP

google-cloud-platformgoogle-compute-enginegoogle-stackdrivernginx

Cloud Monitoring Uptime checks allow users to send a request to a resource to see if it respond.

Since the checks are performed outside Google Cloud infrastructure, an external ip is needed.

Is there a way to implement Uptime checks for sites ( http requests ) that does not have a public IP?

Best Answer

TL;DR: yes, by using a bastion host with external IP that can query reach the internal site and use a proxy ( NGINX , SquidProxy , etc ) to pass your health check request from the external services to your internal sites.

What you need:

  1. A VM with external IP in the same VPC of your private VMS ( the ones without public ip).
  2. Communication between the VM with external IP (from now referred as probe vm ) and the VMs that host your internal websites.
  3. (optional, but highly recommended) Your website should have a health-check webpage. This page should return a 200 if the site and system it’s ok and preferably an authentication protection.

The process:

  1. Create a VM within the same VPC where your internal website is. You can create basic linux VM running your preferred linux distribution. The size of your VM can be a n1-standard-1 or a e2-standard-2 the size really depends on how many sites you will monitor. You may need to adjust the size of your VM according to your needs.
  2. Allow communication between your probe vm and the internal vms that host your site. It’s recommended that you only allow the ports used by your internal sites.
  3. Restrict all traffic to your your probe vm to avoid any type of data leak. Use Google Cloud Firewall to achieve this. ( note: do not forget to whitelist your IP for port 22 so you can manage your probe vm )
  4. Allow HTTP (port 80) traffic to your probe vm to Cloud Monitoring ips.
  5. Install NGINX Opensource on your probe vm.

If you want to skip the installation process, you may choose to use NGINX PLUS and install it by using Google Cloud MarketPlace

You can also use NGINX Docker container for this task.

  1. Configure NGINX as Reverse Proxy
  2. Create your Uptime checks in Cloud Monitoring.

Some tips and tricks on how to configure nginx

When you install NGINX by following NGINX’s instructions, you will get a functional NGINX at the end of the process. But you may need extra configurations to achieve the goal.

  1. Modify the file /etc/nginx/conf.d/default.conf to answer a 404 to any request that does not includes a valid HOST header:
server {
    listen       80 default;
    location / {
        return 404;
    }
}
  1. Create a configuration file under /etc/nginx/conf.d/ directory for each site you want to monitor. i.e. /etc/nginx/conf.d/finance-sites.conf. Do not forget the .conf termination.

  2. Set a bogus host for each site you want to monitor and do not forget to set the host header in Cloud Monitoring.

  3. Do not forget to check syntax nginx -t and reload configuration nginx -s reload each time you perform a change in your configuration.

Related Topic