# Quick Reference for GCP Cloud Shell

## Set the default Project&#x20;

```
$ gcloud compute set project <PROJECT ID>
```

{% hint style="info" %}
&#x20;`set project` will use the selected project as the default project while working in the cloud shell.&#x20;
{% endhint %}

you can use `compute/region` and `compute/zone` to specify the zone or region&#x20;

```
gcloud config set compute/region REGION 
```

```
gcloud compute project-info describe --project PROJECT_ID
```

&#x20;**create an image with a start up script for Apache.**&#x20;

```
gcloud compute instances create web-server \
--image-family debian-9 \
--image-project debian-cloud \
--zone us-central1-b \
--tags http-server \
--metadata startup-script="#! /bin/bash
  sudo apt-get update
  sudo apt-get install apache2 -y
  sudo service apache2 restart
  echo '<!doctype html><html><body><h1>Web Server</h1></body>
  </html>' | sudo tee /var/www/html/index.html
  EOF"
```

**Create an Unmanaged instance group**&#x20;

{% hint style="info" %}
note: un-managed instance groups do not offer auto scaling. typical use case can be for applying load balancing for existing configurations or groups of non identical instances meaning virtual machines.
{% endhint %}

```
gcloud compute instance-groups unmanaged create web-group \
--zone us-central1-b

gcloud compute instance-groups unmanaged add-instances web-group
--instances web-server \
--zone us-central1-b
```

&#x20;**Create an HTTP health check**&#x20;

```
gcloud compute health-checks create http http-health-check
```

&#x20;**Create a managed instance group**

{% hint style="success" %}
&#x20;When creating managed instance groups we are utilizing the the image template created for the managed instance group. you can create an image template before creating an managed instance group or while created the managed instance group.&#x20;
{% endhint %}

{% hint style="info" %}
Managed instance groups gives us with the ability to scale out our resources automatically in the event of heavy traffic. when using load balancing configurations on the google cloud platform target pools or managed instance groups are required when using the auto scale features.&#x20;
{% endhint %}

`gcloud compute --project "your project name here" instance-groups managed create "instance-group-autoscale" --region "us-east1" --base-instance-name "instance-group-autoscale" --template "instance-template-1" --size "1"`

```
gcloud compute --project "your project name here" instance-groups managed set-autoscaling "instance-group-autoscale" --region "us-east1" --cool-down-period "60" --max-num-replicas "10" --min-num-replicas "1" --target-cpu-utilization "0.8"
   
```

&#x20;**Regional groups are recommended over zonal groups**

&#x20;With regional groups your workloads are spread across multiple zones from the same region. Static external IP addresses are considered regional resources while persistent disk and instances are considered zonal.

&#x20;**Zonal groups** - Spans instances across the same zone. zonal resources can only be used by other resources in the same zone.&#x20;

&#x20;**Working with machine types**&#x20;

When using cloud shell we can see the available machine types using this command.when using this command all available machine types will be listed, bur what if we wanted to see only the first 5?&#x20;

```
gcloud compute machine-types list #gives a list of all available machine types 
```

&#x20;let’s get only the first 5 machine types from that list&#x20;

```
gcloud compute machine-types list --limit 5 
```

**custom machine types** \
When creating a custom machine type memory must be in increments of 256 MB \
**1vCPU** would need at least **1GB** of memory, if your using a shared 1vCPU then the 0.6 GB would work but only under that configuration.&#x20;

\
you can add extended memory to custom machine types. Predefined machine types are not supported, an instance can have up to 6.5 GB memory per 1vCPU.&#x20;

```
gcloud compute instances create example-instance --custom-cpu 4 --custom-memory 5 #creates an instance with 4 vCPU and 5 GB memory 
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://preston.gitbook.io/cloud-eng/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
