Problem
You have a requirement to start running your applications as containers. You want to get started with Compute Engine, and you want to run your NGINX as a container. You also want the benefits that Kubernetes provides, such as autoscaling, autohealing, and rolling updates.
Solution
Create a new Docker container. You will then deploy the Docker container to an instance group that will provide the autoscaling, autohealing, and rolling update requirements for your application. Instance groups provide you with benefits similar to Kubernetes, because it allows you to create MIGs to provide autoscaling, autohealing, and automatic updating.
- Sign in to Google Cloud Console and launch Cloud Shell.
- Create a new instance template and associate it with a publicly accessible container image. Run the following command in your Cloud Shell:
gcloud compute instance-templates create-with-container nginx-template \
--container-image gcr.io/cloud-marketplace/google/nginx1:1.15 \
--tags http-server
- Create a target pool so you have a single access point for load balancing. Run the following command:
gcloud compute target-pools create nginx-pool
- Run the following command to create an instance group based on the newly created template:
gcloud compute instance-groups managed create nginx-group \
--base-instance-name nginx-vm \
--size 2 \
--template nginx-template \
--target-pool nginx-pool
- Run the following command to create a regional load balancer for the newly created instance group:
gcloud compute forwarding-rules create nginx-lb \
--ports 80 \
--target-pool nginx-pool