Compute Engine
Launching Instances
- Click buger menu icon (on the top left) > Compute Engines > VM instances
- then click
Create instancebutton on the top bar menu (under the search bar) - There are 7 side menus: Machine configuration, OS and storage, Data protection, Networking, Observability, Security, and Advanced. We’re going to set just some of them - to reduce the learning cost - and left the rest as default. Feel free to play around with it.
- Machine configuration
- set Name, Region and Zone as you wish
- choose
e2-micromachine type withspotprovisioning model
- On the “OS and storage” configuration, click “Change” button. Let OS version as it is (Debian) but change the “Boot disk type” to “Standard persistent disk”
- Machine configuration
- Click “Create” button on the bottom. Then you’ll see the vm instance you just created.
Instance with script
You can install some packages during the initialization. From the step 3 above, click the “Advanced” configuration and add “Startup script” (more info see https://docs.cloud.google.com/compute/docs/instances/startup-scripts), for example
|
|
Ensure you have “External IPv4 address” set up on the “Networking - Edit network interface” configuration and check “Allow HTTP(s) traffic”
My Cheap Instance
I use spot model (see https://docs.cloud.google.com/compute/docs/instances/spot) for learning or experiment since it is very affordable. Here is my instance configuration
|
|
whereas test-vm-jkt is the instance name. Get project id using command gcloud projects list or check via console. Try to change flag --no-restart-on-failure to --restart-on-failure, since it is SPOT model, the flag will be ignored. if you want to create self-healing spot vm, use MIG template to create the instance.
SSH connection
- ensure you’re set on the right project, check via
gcloud config list - if not, set the project
gcloud config set project PROJECT_ID. you can see the PROJECT_ID viagcloud projects list - ensure the instance you want to connect is on the list via
gcloud compute instances list, remember theNAMEof the instance that you want to connect.- if you find the instance status is TERMINATED, you shall activate with
gcloud compute instances start INSTANCE_NAME --zone ZONE_NAME - changing
starttostopabove for terminating the instance, if you want to play arround
- if you find the instance status is TERMINATED, you shall activate with
- if it’s okay, run
gcloud compute ssh INSTANCE_NAME --project PROJECT_ID- you may add flag
--tunnel-through-iapto make it work - some distro require username, e.g. Fendora run
gcloud compute ssh core@test-vm-1 --zone=us-central1-f.
- you may add flag
- if you face the problem during connection, you can check the vm detail with command
gcloud compute instances describe INSTANCE_NAME
Kubernetes Service
We learn how to orchestrate containers with Google Kubernetes Engine (GKE)