Week10 - Selesfia/ComputerNetwork GitHub Wiki
- Create new instance -> Give a name "myvm1" -> Set the zone to "asia-east1-a" -> Choose N1 machine type -> Change the OS to "Ubuntu" -> Allow HTTP traffic -> Network interfaces -> choose "myvpc1" -> At automation paste the below script -> Create
#! /bin/bash
apt update
apt -y install apache2
cat <<EOF > /var/www/html/index.html
<html><body><p>Linux startup script added directly. $(hostname -I) </p></body></html>
- Create new instance -> Give a name "myvm2" -> Set the zone to "asia-east1-a" -> Choose N1 machine type -> Change the OS to "Ubuntu" -> Allow HTTP traffic -> Network interfaces -> choose "myvpc1" -> At automation paste the below script -> Create
#! /bin/bash
apt update
apt -y install apache2
cat <<EOF > /var/www/html/index.html
<html><body><p>Linux startup script added directly. $(hostname -I) </p></body></html>
- New unmanaged instance group -> Give a name "mygroup" -> Set the zone "asia-east1-a" -> Network "myvpc1" -> Choose VM instances "myvm1" and "myvm2" -> Create
- Type of load balancer "Application Load Balancer (HTTP/HTTPS)" -> Public facing or internal "Public facing (external)" -> Global or single region deployment "Best for regional workloads" -> Configure
- Give a name "mylb" -> Set region "asia-east1" -> Network "myvpc1", Proxy-only subnet: myvpc1-proxy-subnet 10.0.0.0/24 -> Create front end "myfrontend" -> Create back end "mybackend" -> Choose instance group "mygroup" -> Set port number to 80 -> Create health check "myheathcheck" -> Save -> Create
- Create -> Give a name "myvpc1-allowhttp2" -> Network "myvpc1" -> Target tags "http2" -> Source IPv4 "10.0.0.0/8" -> Port "80" -> Create
- Create -> Give a name "myvpc1-allow-hc" -> Network "myvpc1" -> Target tags "hc" -> Source IPv4 "35.191.0.0/16", "130.211.0.0/22" -> Port "80" -> Create
- Edit myvm1 -> Disable HTTP traffic -> Network tags add "http2", "hc" -> Set external IP to "none" -> Save
- Edit myvm2 -> Disable HTTP traffic -> Network tags add "http2", "hc" -> Set external IP to "none" -> Save
Result
- Give a name "my-template1" -> Set region "asia-east1" -> Machine configuration "N1" -> Change Boot disk "Ubuntu" -> Allow HTTP traffic -> Paste below script at Automation -> Create
#! /bin/bash
apt update
apt -y install apache2
cat <<EOF > /var/www/html/index.html
<html><body><p>Linux startup script added directly. $(hostname -I) </p></body></html>
- New managed instance group (stateless) -> Give a name "mygroup2" -> Instance template "my-template1" -> Location "multiple zone" -> Max number of instances "1" -> Min number of instances "3" -> Create health check "instance-group-hc" -> Check interval "10", timeout "10" -> Healthy threshold "3" -> Unhealthy threshold "3" -> Create
- SSH to VM that is created by instance template ->
cat /dev/zero > /dev/null
Before
After
If it over than 60%, then it will create more instance
- Type of load balancer "Application Load Balancer (HTTP/HTTPS)" -> Public facing or internal "Public facing (external)" -> Global or single region deployment "Best for regional workloads" -> Configure
- Give a name "mylb2" -> Set region "asia-east1" -> Network "Default", Proxy-only subnet: proxy-subnet 10.0.0.0/24 -> Create front end "myfe" -> Create back end "mybe" -> Choose instance group "mygroup2" -> Set port number to 80 -> Create health check "myhc" -> Save -> Create
- Access the load balancer ip address
PS : Remember to delete the resources that you created if you don't use it anymore.
12/11/2024