Aditya Sharma
Aditya Sharma

Reputation: 81

NGINX instance problems

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?

Upvotes: 7

Views: 13830

Answers (4)

Deepak Bajaj
Deepak Bajaj

Reputation: 250

This google task is bit confusing, You don't need to have any instances running to complete this task, Kindly follow the below steps on a fresh space.

You can follow below steps to complete the task -

  1. First Create a startup.sh file, Run the command below
cat << EOF > startup.sh
#! /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. Now, Create an instance template
gcloud compute instance-templates create lb-backend-template --region=us-east1 --network=default --subnet=default --tags=allow-health-check --machine-type=e2-medium --image-family=debian-11 --image-project=debian-cloud --metadata-from-file startup-script=startup.sh
  1. Further, Create a managed instance group
gcloud compute instance-groups managed create lb-server-group --base-instance-name lb-server --size 2 --template lb-backend-template --region us-east1
  1. Now we need to create a firewall rule to allow traffic (80/tcp)
gcloud compute firewall-rules create lb-server-firewall --allow tcp:80 --network default ```
  1. Create a health check using the below command
gcloud compute http-health-checks create http-check
  1. Create a backend service and attach the managed instance group
gcloud compute instance-groups managed set-named-ports lb-server-group --named-ports http:80 --region us-east1
  1. Create a backend service and attach the managed instance group
gcloud compute backend-services create lb-server-backend --protocol HTTP --http-health-checks http-check --global
  1. Create a URL map and target HTTP proxy to route requests to your URL map
gcloud compute backend-services add-backend lb-server-backend --instance-group lb-server-group --instance-group-region us-east1 --global

gcloud compute url-maps create lb-server-map --default-service lb-server-backend

gcloud compute target-http-proxies create http-lb-proxy --url-map lb-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

NOTE :- Now wait for 5/7 minutes to see the website behind the HTTP load balancer

Lastly you can also change the names of the services as per your requirements

Upvotes: 1

sskela
sskela

Reputation: 1

To the previous comment, I would only add that there is one extra line needed -

 gcloud container clusters create nucleus-jumphost-webserver1 

Taken from here - https://gist.github.com/Tambunan26/9063521fdf406645aad4527ccd069149

Upvotes: 0

Ankit Bajpai
Ankit Bajpai

Reputation: 13517

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.

Upvotes: 11

Frank
Frank

Reputation: 545

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.

Upvotes: 1

Related Questions