DEV Community

Cover image for Google Cloud Fundamentals Part 1
Shahriyar Al Mustakim Mitul
Shahriyar Al Mustakim Mitul

Posted on

Google Cloud Fundamentals Part 1

Regions
There are specific geographical locations to host one's resources and it is called Region. Google has almost 20+ regions. Usages: Availability, Low latency, global footprint, adherence to government.

Zones/Discrete Cluster
Each region has more than one zones. Generally 3 zones. For example: us-west1 regions has zone us-west1-a,us-west1-b,us-west1-c.

Google Compute Engine
Enables to create and manage Virtual Machine. Gives one to load balance and auto-scale multiple virtual machine instances, attach storage and network storage, manage network connectivity and configuration.
Create a virtual machine instance( Hands-on):

  1. Go o Google Console and search for "Compute Engine". Press Create
  2. Give it a name and add labels. For example, the "environment" key can have "dev" value, "business" key with "sales" value etc. with a save.
  3. Choose a region and zone.
  4. From the Machine Configuration, choose Machine Family based on your need. For example, choose 'General purpose' and keep others as default.
  5. From the boot disk, select the image/operating system you want to use.
  6. Under the Firewall, we are going to select Allow HTTP Traffic to allow a person from outside with http website can get into our VM. Then press "Create". Now go to VM Instances and you can find your instance. You can see the external IP address which we will use to talk to the machine.

Note: You can also press 'SSH' to work with the VM instance through the terminal. Now we are going to install a http webserver on GCP VM.

sudo su to become the root user. To update all package managers apt update. Now to install apache, apt install apache2.
Now go to see the http server, go to the external IP and see the page

Image description
As the default root is here /var/www/html, we are going to use it

Image description
thus use ls /var/www/html. Now going to edit "Hello world" in the index.html file
echo "Hello World!" > /var/www/html/index.html
Now go to the External IP address and you may see

Image description
Now to print the host name( Virtual machine name), we are going write echo $(hostname) and to get the Internal IP address, echo $(hostname -i)

Image description
To pass all these information to our index page, we can use echo "Hello world from $(hostname) $(hostname -i)" > /var/www/html/index.html

Image description

And we can see the output:

Image description

Basics of VM IP address
Internal IP address does not change and unique for a VM
External IP address changes when someone stop the VM. External users use the VM using External IP address.
Static IP address is Permanent External IP address that can be attached to a VM. To create a static IP address, go to VPC Network and then External IP address and press Reserve Static Address to make your selected External IP address as a static one. Or manually search for External Ip address from the search bar and then from the dropdown, select "Static"

Image description
You can then give it a name

Image description
As it is a premium thing, you need not to use static one if you are not using it. Just go to external IP address under VPC Network and press "Change" and Attach IP address to None.

Simplify VM HTTP Server setup

  1. Using startup script: Go to VM Instances and press create. Give it a name and go to "Management, security, disk,..." and go to Startup script. add this code
#!/bin/bash
apt update 
apt -y install apache2
echo "Hello world from $(hostname) $(hostname -I)" > /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode

and press Create

  1. Instance Template: Rather than creating instances manually every time, we can create instance templates.

Image description
Now, under the Compute Engine, go to Instance Templates. Create a new.

Image description
add the default disk and others and again add Startup Script like the previous example with the same code.

Note: We need to pay if we create a VM using the Instance Template.

  1. Use a custom image

Image description
Under the Compute engine, go to storage and choose "Disks"(Hard disk associated with your virtual machine). Assume that we have a VM already created and thus a Disk already there.

Now go to "Actions" and go to "Create Image"
Note: You should not create an image from a disk that is currently attached to a running instance. You should stop the instance and then create an image from that disk.
Give the image a name and press "Create".

Image description
Now you will find a disk and you can create an instance from your custom disk.
You can now create instance templates using your custom disk. While creating instance templates, you need to choose your disk inn the "Boot disk" section.

Image description
Use discounts

  1. Sustainable
    Image description

  2. Committed use discount

Image description

  1. Preemptible VM

Image description
Image description

Sole Tenant Nodes

Image description
Image description
Press 'Create a Node group'. Under the node template properties, create a node template and remember to select Affinity Labels. For example: key="group" and value="a". You can choose number of nodes as 1. Thus you can create one.
Note: Sole tenants are very expensive and we will refrain from making this.
While creating a VM instance, go to Management,disk ,........
Image description
Add the affinity label we created
Image description
So, what basically happens is that if we have a key and value created with this, the VM is getting created under that node.

Google Cloud Pricing Calculator
Calculator

Oldest comments (0)