Writing

Google Cloud Services basics

GeneralGoogle CloudTech trends30 days of google cloudCloud armorFirewallGCSIAMIAPPub/Subapache benchcloudcloud functionscloud monitoringcloud storagegoogle cloud servicesload balencingvirtual machinevirutal private cloud

Hi, so I was one of the Google cloud Facilitators for this year. This blog contains a list of all the cloud services offered by google which were covered in the Cloud Engineering Track.

Virtual Machine:

A virtual machine can be simply defined as creating a computer within a computer, which can run on different OS. A virtual machine can’t tamper or interfere with the computer itself but is an excellent way to run an ideal environment for programs.

Compute Engine lets you create virtual machines that run different operating systems, including multiple flavours of Linux and Windows Server

Certain Compute Engine resources live in regions or zones. A region is a specific geographical location where you can run your resources. Each region has one or more zones. For example,

[Image no longer available]

To check information about default region and zone, type this in the cloud shell

gcloud config get-value compute/zone
gcloud config get-value compute/region

Resources that live in a zone are referred to as zonal resources. Virtual machine Instances and persistent disks live in a zone. To attach a persistent disk to a virtual machine instance, both resources must be in the same zone. Similarly, if you want to assign a static IP address to an instance, the instance must be in the same region as the static IP.

[Image no longer available]

You can create a Virtual machine from cloud console or from the cloud shell.

For more information,

  1. https://cloud.google.com/compute/docs/instances/

Virtual Private Cloud (VPC):

A Virtual Private Cloud (VPC) network is a virtual version of a physical network. Every instance in a VPC network has a default network interface. You can create additional network interfaces attached to your VMs.

Multiple network interfaces enable you to create configurations in which an instance connects directly to several VPC networks (up to 8 interfaces, depending on the instance’s type).

You can create the VM instance with multiple network interfaces, and explore network interface details and connectivity.

You can configure custom firewall rule and explore the network and security admin roles.

For more information,

  1. https://cloud.google.com/vpc/docs/vpc

Network and Load Balancing:

2.1.Multiple web server instances

To simulate serving from a cluster of machines, create a simple cluster of Nginx web servers to serve static content using,

1.Instance templates :

An instance template is a resource that you can use to create Virtual Machine (VM) instances and managed instance groups (MIGs).

Instance templates define the machine type, boot disk image or container image, labels, and other instance properties. Use instance templates any time you want to quickly create VM instances based off of a preexisting configuration.

2.Managed instance groups:

Can operate apps on multiple identical VMs. You can make your workloads scalable and highly available by taking advantage of automated MIG services, including auto-scaling, auto-healing, regional (multiple zones) deployment, and automatic updating.

Managed instance groups (MIGs) are suitable for scenarios like these:

  1. Stateless serving workloads, such as a website front end
  2. Stateless batch, high-performance, or high-throughput compute workloads, such as image processing from a queue
  3. Stateful applications, such as databases, legacy applications, and long-running batch computations with checkpointing

Each managed instance in a MIG is created from an instance template.

[Image no longer available]

To create the Nginx web server clusters, steps to be followed:

  1. A startup script to be used by every virtual machine instance to set up Nginx server.
  2. An instance template to use the startup script.
  3. A target pool, allows a single access point to all the instances in a group and is necessary for load balancing.
  4. A managed instance group.
  5. Check if the computer engine instance has been created or not.
  6. Configure your fire wall rules to allow tcp traffic over port 80
2.2.Network Load balancer:

Network load balancing allows you to balance the load of your systems based on incoming IP data, such as address, port, and protocol type.

[Image no longer available]

You also get some options that are not available with HTTP(S) load balancing. For example, you can load balance additional TCP/UDP based protocols, such as SMTP traffic.

2.2.1.HTTP(S) load balancing in depth:

HTTP(S) load balancing provides global load balancing for HTTP(S) requests directed to your instances. You can configure URL rules to route some URLs to one set of instances and route other URLs to other instances.

Requests are always routed to the instance group that is closest to the user, if that group has enough capacity and is appropriate for the request. If the closest group does not have enough capacity, the request is sent to the closest group that does have capacity.

A forwarding rule sends traffic to a specific target HTTP or HTTPS proxy depending on the IP address, IP protocol, and port specified. The global forwarding rule does not support multiple ports.

For more information,

  1. https://cloud.google.com/load-balancing/docs/load-balancing-overview#a_closer_look_at_cloud_load_balancers
  2. https://cloud.google.com/compute/docs/load-balancing/network/

Cloud Storage:

Cloud Storage allows world-wide storage and retrieval of any amount of data at any time. You can use Cloud Storage for a range of scenarios including serving website content, storing data for archival and disaster recovery, or distributing large data objects to users via direct download.

You can create/delete folder, upload items into these folders. You can also share the object publicly.

Cloud IAM:

Google Cloud’s Identity and Access Management (IAM) service lets you create and manage permissions for Google Cloud resources. Cloud IAM unifies access control for Google Cloud services into a single system and provides a consistent set of operations.

[Image no longer available]

You can add roles to users and restrict the utilization over cloud resources. Such as give read permission to all, and write permission to certain users.

For more information,

1.https://cloud.google.com/iam/docs/understanding-roles#primitive_roles

Cloud Monitoring:

Cloud Monitoring provides visibility into the performance, uptime, and overall health of cloud-powered applications.

Cloud Monitoring collects metrics, events, and metadata from Google Cloud, Amazon Web Services, hosted uptime probes, application instrumentation, and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch, and many others.

Cloud Monitoring ingests that data and generates insights via dashboards, charts, and alerts. Cloud Monitoring alerting helps you collaborate by integrating with Slack, PagerDuty, HipChat, Campfire, and more.

[Image no longer available]

1.Install the monitoring and logging agents:

An Agents collect data and then send or stream info to Cloud Monitoring in the Cloud Console.

The Cloud Monitoring agent is a collected-based daemon that gathers system and application metrics from virtual machine instances and sends them to Monitoring. By default, the Monitoring agent collects disk, CPU, network, and process metrics.

(In multitasking computer operating systems, a daemon is a computer program that runs as a background process, rather than being under the direct control of an interactive user.)

Install agents on a VM:

1.Run the Monitoring agent install script command in the SSH terminal of your VM instance to install the Cloud Monitoring agent.

curl -sSO https://dl.google.com/cloudagents/add-monitoring-agent-repo.sh
sudo bash add-monitoring-agent-repo.sh

sudo apt-get update

sudo apt-get install stackdriver-agent

2.Run the Logging agent install script command in the SSH terminal of your VM instance to install the Cloud Logging agent

curl -sSO https://dl.google.com/cloudagents/add-logging-agent-repo.sh
sudo bash add-logging-agent-repo.sh

sudo apt-get update

sudo apt-get install google-fluentd

For more information,

  1. https://cloud.google.com/monitoring/agent
2.Create an uptime check:

Uptime checks verify that a resource is always accessible. For example, create an uptime check to verify your VM is up.

[Image no longer available]

3.Create an alerting policy:

Use Cloud Monitoring to create one or more alerting policies. Alerting gives timely awareness to problems in your cloud applications so you can resolve the problems quickly.

To create an alerting policy, you must describe the circumstances under which you want to be alerted and how you want to be notified.

[Image no longer available]

For more information,

  1. https://cloud.google.com/monitoring/alerts/

Cloud Functions:

Cloud Functions is a serverless execution environment for building and connecting cloud services. With Cloud Functions you write simple, single-purpose functions that are attached to events emitted from your cloud infrastructure and services.

Your Cloud Function is triggered when an event being watched is fired. Your code executes in a fully managed environment. There is no need to provision any infrastructure or worry about managing any servers.

Cloud Functions are written in Javascript and execute in a Node.js environment on Google Cloud. You can take your Cloud Function and run it in any standard Node.js runtime which makes both portability and local testing a breeze.

Cloud Functions provides a connective layer of logic that lets you write code to connect and extend cloud services.

1.Events and Triggers:

Cloud events are things that happen in your cloud environment. These might be things like changes to data in a database, files added to a storage system, or a new virtual machine instance being created.

Events occur whether or not you choose to respond to them. You create a response to an event with a trigger. A trigger is a declaration that you are interested in a certain event or set of events. Binding a function to a trigger allows you to capture and act on events.

For more information

  1. https://cloud.google.com/functions/docs/concepts/events-triggers

2.Serverless:

Cloud Functions removes the work of managing servers, configuring software, updating frameworks, and patching operating systems. The software and infrastructure are fully managed by Google so that you just add code. Furthermore, provisioning of resources happens automatically in response to events. This means that a function can scale from a few invocations a day to many millions of invocations without any work from you.

For more information,

  1. https://cloud.google.com/serverless/

Use cases:

The fine-grained, on-demand nature of Cloud Functions also makes it a perfect candidate for lightweight APIs and web-hooks.

Pub/ Sub :

Google Cloud Pub/Sub is a messaging service for exchanging event data among applications and services. A producer of data publishes messages to a Cloud Pub/Sub topic. A consumer creates a subscription to that topic. Subscribers either pull messages from a subscription or are configured as web-hooks for push subscriptions. Every subscriber must acknowledge each message within a configurable window of time.

[Image no longer available]

With Pub/ Sub you can ,

  1. Set up a topic to hold data.
  2. Subscribe to a topic to access the data.
  3. Publish and then consume messages with a pull subscriber.
  4. View the message

[Image no longer available]

For more information,

1.https://developers.google.com/pubsub/overview

Firewall Rules:

You can create custom firewall rules with custom tags

The default-allow-internal firewall rule allows traffic on all protocols/ports within the default network. You want to create a firewall rule to allow traffic from outside this network to only the blue server, by using the network tag web-server.

Make sure to include the /0 in the Source IP ranges to specify all networks.

Deployment Manager:

Google provides a robust set of sample Deployment Manager templates that you can learn from and build upon. To clone the repository, enter the following commands in Cloud Shell Command Line to create a directory to hold the Deployment Manager sample templates.

For example,

git clone https://github.com/GoogleCloudPlatform/deploymentmanager-samples.git

You can explore the sample files

The main deployment manager configuration file is nodejs.yaml. It makes use of templates to generate infrastructure. The rest of the files are templates. Templates use variables defined in the nodejs.yaml configuration file to produce customized results.

The files included are

1.frontend.py

frontend.py includes frontend.py.schema, which creates an instance template based on container_instance_template.py. This template is used to create a managed instance group and an autoscaler. The template also creates a network load balancer that has a forwarding rule with a single public IP address. It also creates:

  1. A target pool that refers to the managed instance group.
  2. A health check attached to the target pool.

2.nodejs.py

nodejs.py includes nodejs.py.schema, which brings the frontend and backend templates together.

  1. Note that the frontend is frontend.py.
  2. The backend is /common/python/container_vm.py.
  3. This is a VM running a Docker container with MySQL, so it doesn’t require a custom template.

3.Other files

  1. /common/python/container_instance_template.py
  2. /common/python/container_vm.py
  3. /common/python/container_helper.py

You can modify the files for customizing the deployment, such as

  1. zones
  2. maximum number of instances in the instance group

Now you’ll use Deployment Manager to deploy the application and make it operational. This builds the infrastructure, but it won’t allow traffic. After Deployment Manager sets up the infrastructure, you can apply service labels.

gcloud deployment-manager deployments create advanced-configuration --config nodejs.yaml

To verify that the application is running, open a browser to access port 8080 and view the service. Since the IP address was established dynamically when the Deployment Manager implemented the global forwarding rule (specified in the template), you’ll need to find that address to test the application.

Find the global load balancer forwarding rule IP address

gcloud compute forwarding-rules list

Open a window in your browser and

http://<your IP address>:8080

[Image no longer available]

For more information,

  1. https://cloud.google.com/deployment-manager/docs/create-advanced-http-load-balanced-deployment

Apache Bench :

You’ll use Apache Bench to apply load to the service. Watch the DMDash dashboard in Cloud Monitoring to monitor the CPU usage and the Network Inbound Traffic. You’ll also be able to track the number of instances in Cloud Monitoring by mousing over the lines, or by viewing the instances in the Cloud Console

Install Apache Bench:

  1. Still in the VM Instances window, click the instance-1 SSH button to SSH into the VM you just created.
  2. Enter the following commands to install the latest ApacheBench:
sudo apt-get update

sudo apt-get -y install apache2-utils

In the SSH window, enter this command for Apache Bench to apply load to the service. Replace your forwarding IP for Your_IP

ab -n 1000 -c 100 http://<Your_IP>:8080/

Run this command two or three times to create traffic,

1.With Auto scaling:

Expected behavior: The load consumed more than 20% of the cumulative CPU in the group, triggering auto scaling. A new instance was started.

2.Without Auto scaling:

Expected behavior: With auto scaling off, no new instances are created, cumulative CPU usage increases.

[Image no longer available]

For more information,

  1. https://cloud.google.com/load-balancing/

Identity-Aware Proxy (IAP):

Identity-Aware Proxy (IAP) restricts access to the application and provide user identity information to it.

Authenticating users of your web app is often necessary, and usually requires special programming in your app. For Google Cloud Platform apps you can hand those responsibilities off to the Identity-Aware Proxy service.

If you only need to restrict access to selected users there are no changes necessary to the application. Should the application need to know the user’s identity (such as for keeping user preferences server-side) Identity-Aware Proxy can provide that with minimal application code.

Identity-Aware Proxy (IAP) is a Google Cloud Platform service that intercepts web requests sent to your application, authenticates the user making the request using the Google Identity Service, and only lets the requests through if they come from a user you authorize. In addition, it can modify the request headers to include information about the authenticated user.

Steps for using IAP,

  1. Deploy to App Engine
  2. Restrict access with IAP
    1. Enable IAP API
    2. Accept the consent screen
    3. Create a IAP
  3. Disable Flex API

App Engine has its Protocol for using IAP standard and flexible environments which are optimized for different application architectures. Currently, when enabling IAP for App Engine, if the Flex API is enabled, GCP will look for a Flex Service Account.

You can further add members or examine the application files.

If there is a risk of IAP being turned off or bypassed, your app can check to make sure the identity information it receives is valid. This uses a third web request header added by IAP, called X-Goog-IAP-JWT-Assertion. The value of the header is a cryptographically signed object that also contains the user identity data.

Cloud Armor:

Cloud Armor IP allow list/deny list enable you to restrict or allow access to your HTTP(S) load balancer at the edge of the Google Cloud, as close as possible to the user and to malicious traffic. This prevents malicious users or traffic from consuming resources or entering your virtual private cloud (VPC) networks.

Steps to use cloud armor,

  1. Configure HTTP and health check firewall rules.
  2. Configure instance templates and create instance groups
  3. Configure the HTTP load balancer
  4. Stress test the HTTP Load Balancing
  5. Verify the security policy

You can stress test the HTTP load balancing by using a VM, click on the SSH

sudo apt-get -y install siege

export LB_IP=[LB_IP_v4]

siege -c 250 http://$LB_IP
Internal Load Balancing:

Google Cloud offers Internal Load Balancing for your TCP/UDP-based traffic. Internal Load Balancing enables you to run and scale your services behind a private load balancing IP address that is accessible only to your internal virtual machine instances.

An Internal Load Balancer is a regional service. The managed instance groups will be in different zones, making your service immune to zonal failures.

Managed instance groups offer auto scaling capabilities that allow you to automatically add or remove instances from a managed instance group based on increases or decreases in load. Auto scaling helps your applications gracefully handle increases in traffic and reduces cost when the need for resources is lower. You just define the auto scaling policy and the autoscaler performs automatic scaling based on the measured load.

Configure the Internal Load Balancer to balance traffic between the two back ends. This choice requires the backends to be in a single region (us-central1) and does not allow offloading TCP processing to the Load Balancer.

For basics of Google Kubernetes Engine, Docker, Jenkins, Spinnaker and CI/CD Pipelines:

https://programmerprodigy.code.blog/2020/11/10/google-kubernetes-engine-basics/

I have mostly picked up information from Google documentation, and pictures i have used to explain concepts are not by me, I just found them online.