Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 4, 2022 08:26 am GMT

Google Cloud Fundamentals Part 3

Managed Services

Image description
IAAS

Image description
PAAS

Image description

Containers Basics

Image description

In a virtual machine in addition to hostOS, there is guestOS.
Docker is cloud-neutral and you can run it anywhere9AWS, GCP, Azure)

Image description
Container Orchestration
This basically makes images based on your needs. Ex: Kubernetes.
Benefits: They can provide autoscaling, help one service find another, load balancing, provide health checks, zero downtime deployments.

Image description
Serverless

Image description
SAAS

Image description
Shared Responsibility

Image description
GCP Services based on Managed

Image description

App Engine

Image description

Compute engine vs App Engine

Image description

Types of App Engine: 1) Standard 2) Flexible

Image description
Let's create an APP engine
1) First create a project under your GCP account and enter into it.
2) Go to "App Engine Admin API" and enable it.
3) Go to "App Engine" and create the Application.
4) Select the default options and create app.

Image description
5) Select the terminal and then press "Open editor". Then add a folder named "default-service" and add "app.yaml" with these codes:

runtime: python39

a folder named "main.py":

from flask import Flaskapp = Flask(__name__)@app.route('/')def hello():    return 'My Default Service - V1'

a file named "requirements.txt" with these codes:

Flask==2.0.2

Now let's use the terminal to configure to our desired project.

cd default-servicegcloud config set project <Project ID>

Now deploy the app:

gcloud app deploy

and press Y. You may see this error

Image description
Here while deploying there was a cloudbuild service account was automatically created which need the permission of 'Storage Object Viewer" as it will work with the store.
SO go to IAM & Admin and give this cloudbuild service account a role of Storage Object Viewer.

Image description
Now you can deploy things perfectly. You can check out all of the services created with these codes:

gcloud app services listgcloud app versions listgcloud app instances list

Note: When we deployed the app for the first time,gcp automatically assigned us the version number. now let's change code in main.py and give it a new version and deploy.
main.py will have:

from flask import Flaskapp = Flask(__name__)@app.route('/')def hello():    return 'My Default Service - V2'

Now go to terminal and write

gcloud app deploy --version=v2

Now a new version will be deployed and all traffic will be splitted there. Let's check it from this code:

gcloud app versions list

You can see it here.
Image description
You can check the link to check the old version and also current version.
See new version link:

gcloud app browse

To check old version's link which is still running but not serving infront:

gcloud app browse --version <version id>

Google Kubernetes Engine(GKE)

Image description
Let's create a cluster using GKe:

  1. Create a project and enter into it.
  2. Enable API from "Kubernetes Engine API"
  3. Go to Kubernetes Engine and press Create cluster. You may see something like this

Image description
The standard mode lets you manage everything by yourself but Autpilot mode helps you managing them. You don't need to worry that much.

Image description
This is what autopilot does. For now, select Standard mode and Configure.
Give your cluster a name

Image description
Let's connect our project to cloudshell:

gcloud config set project <project id>

Now connecting our cluster with cloud shell project.

gcloud container clusters get-credentials <cluster name> --zone us-central1-c --project <project id>

Let's deploy a microservice (ex: hello-world-rest-api) in this cluster

kubectl create deployment hello-world-rest-api --image=in28min/hello-world-rest-api:0.0.1.RELEASE

Now check the deployment:

kubectl get deployment

To access the deployment, you need to expose it. Exposing using load balacner:

kubectl expose deployment hello-world-rest-api --type=LoadBalancer --port=8080

Now we can check the deployment we created:

kubectl get services

Image description

NOte: Exposing a deployment == service.
Now send a curl request to the External IP of the service you just created.

curl <External IP>:8080/hello-world

I your browser, paste this and see the exposed microservice
:8080/hello-world
Now let's increase our instances:

kubectl scale deployment hello-world-rest-api --replicas=3

scaled the deployment to 3 instances.
Now check the status of it:

kubectl get deployment

now we can see 3 instances which as actually called pods. let's see each of them:

kubectl get pods

Image description
When creating kubernetes cluster, we had 3nodes just.Lets scale down to 2:

gcloud container clusters resize my-cluster --node-pool default-pool --num-nodes=2 --zone=us-central1-c

Note: you need to give your specific node pool from your cluster and also zone already selected.

Image description
You can now see 2 nodes only

Image description

Let's auto scale the based on cpu utilization and set max instances to be 4.

kubectl autoscale deployment hello-world-rest-api --max=4 --cpu-percent=70

Let's autoscale Kubernetes cluster:

gcloud container clusters update <cluster name> --enable-autoscaling --min-nodes=1 --max-nodes=10

Delete the cluster :

gcloud container clusters delete

Delete services:

kubectl delete service <service name>

Delete deployment:

kubectl delete deployment <deployment name>

Now let's delete the cluster once we are within our project:

gcloud container clusters delete <cluster name> --zone <zone>

Cloud Function

Image description
Update: Max: 60min (3600sec)
Let's create a Cloud Function:
Enable Cloud Build API

  1. Search for "Cloud Function" and press "CREATE FUNCTION".
  2. choose 1st gen, give a name to the function, trigger type is HTTP, allow unauthenticated invocations, uncheck Require HTTPS and Save.
  3. Press Next
  4. You can choose the Runtime to default one (Node.js 16)
  5. All other things are going to be the same. Press DEPLOY.

Go to Testing and you can see your output.

Cloud Run
Container to deploy in seconds.
Let's create one:

  1. Go to Cloud Run and press CREATE SERVICE.
  2. Choose Container image from Container Image URL.
  3. Set the service name.
  4. Now allow all traffic and allow unauthenticated invocations.
  5. Press Create.

Image description


Original Link: https://dev.to/mitul3737/google-cloud-fundamentals-part-3-35le

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To