Logo

How to Deploy Containers to Managed Instance Groups

Sep 08, 2021

You need your applications to operate as managed containers. You want your NGINX web server to function as a container via the Cloud Compute Engine. With this method, you can achieve it and benefit from the perks (autoscaling, rolling updates, etc) provided by open-source systems like Kubernetes.

First, you need to set up a new Docker container. Then, you’re going to link the container to your VM Instance Template and enable it so that it can apply autohealing, auto updates and other perks to your group.

Step 1 - Launch Google Cloud Console and log in.

Step 2 - Run the following command to set up a new Instance Template and link it to a publicly accessible container:

gcloud compute instance-templates create-with-container nginx-template \
    --container-image gcr.io/cloud-marketplace/google/nginx1:1.15 \
    --tags http-server

Step 3 - Now, run this command to establish a secure access point for traffic load balancing:

gcloud compute target-pools create nginx-pool

Step 4 - Run a command (below) to set up an Instance Template with the relevant container and access point (steps 2 and 3):

gcloud compute instance-groups managed create nginx-group \
    --base-instance-name nginx-vm \
    --size 2 \
    --template nginx-template \
    --target-pool nginx-pool

Step 5 - Return to the Google Cloud Console. Select the menu displaying your Instance Templates and associated VM groups. Locate the new instance group you’ve just created.

Step 6 - Next, execute the following command to launch the new traffic load balancing rule for the VMs in the group.

gcloud compute forwarding-rules create nginx-lb \
    --ports 80 \
    --target-pool nginx-pool

Step 7 - When asked to input a region, select the most appropriate option for your location (e.g. us-central1).

Step 8 - Now your regional load balancer is activated, find out the new IP address assigned to your VMs. The quickest way to do this is to run this command:

gcloud compute forwarding-rules list

Step 9 - Highlight the IP address to copy it to the clipboard.

Step 10 - Open your browser. Press Ctrl+V to paste the IP address into the search box.

This process is a quick and simple way to launch a managed container via Cloud Compute Engine. There are many more complicated things you can do with containers but this is a valuable place to start if you’re a beginner. Check out Kubernetes for a secure, reliable orchestration engine for your applications if you’re not sure which one to use.