NGINX instance problems

Viewed 4764

This is the screenshot of the problem

I was creating an NGINX instance and while managing the instance group, I am facing this issue. The hint in the cloud says "Please create the managed instance group with 2 NGINX web servers". Stuck up from quite some time, What should I do?

3 Answers

You can follow below steps to complete the task -

Create startup.sh file

#! /bin/bash
apt-get update
apt-get install -y nginx
service nginx start
sed -i -- 's/nginx/Google Cloud Platform - '"\$HOSTNAME"'/' /var/www/html/index.nginx-debian.html
EOF
  1. Create an instance template
gcloud compute instance-templates create web-server-template \
--metadata-from-file startup-script=startup.sh \
--network nucleus-vpc \
--machine-type g1-small \
--region us-east1
  1. Create a managed instance group
gcloud compute instance-groups managed create web-server-group \
--base-instance-name web-server \
--size 2 \
--template web-server-template \
--region us-east1
  1. Create a firewall rule to allow traffic (80/tcp)
gcloud compute firewall-rules create web-server-firewall \
--allow tcp:80 \
--network nucleus-vpc
  1. Create a health check
gcloud compute http-health-checks create http-basic-check
  1. Create a backend service and attach the manged instance group
gcloud compute instance-groups managed \
set-named-ports web-server-group \
--named-ports http:80 \
--region us-east1
  1. Create a backend service and attach the manged instance group
gcloud compute backend-services create web-server-backend \
--protocol HTTP \
--http-health-checks http-basic-check \
--global
  1. Create a URL map and target HTTP proxy to route requests to your URL map
gcloud compute backend-services add-backend web-server-backend \
--instance-group web-server-group \
--instance-group-region us-east1 \
--global

gcloud compute url-maps create web-server-map \
--default-service web-server-backend

gcloud compute target-http-proxies create http-lb-proxy \
--url-map web-server-map
  1. Create a forwarding rule
gcloud compute forwarding-rules create http-content-rule \
--global \
--target-http-proxy http-lb-proxy \
--ports 80

gcloud compute forwarding-rules list

Wait for for extra 10 mins to Create the website behind the HTTP load balancer.

You are trying to use GCP Managed Instance Groups (MIG), and for that you are required to have an Instance Template from where the MIG is going to take the information in order to deploy.

Long story short, you are defining how large you want your resources to be, but you are not specifying what those resources are.

You can follow this guide if you like but here's the short version of it:

gcloud compute instance-templates create nginx-template \
--machine-type e2-standard-4 \
--image-family debian-9 \
--image-project debian-cloud \
--boot-disk-size 250GB

Either that or the template you are using doesn't exist anymore since you are using qwiklabs and those projects get erased after a while.

Related