

Three ways to create GCE on GCP(Console,gcloud,Terraform)
source link: https://www.pkslow.com/archives/create-gcp-gce-en
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

五月畲田收火米,三更津吏报潮鸡。
1 Introduction
We always need to create the GCE(Google Compute Engine) if we use GCP. There are many ways to create GCE:
(1) Create on Console
(2) Create with gcloud
(3) Create with Terraform
For GCP initiation, can go to: How to initiate the GCP project and use gcloud to access.
2 GCP Console
Logon the GCP console and click the button to create GCE VM, select what you need as below:
3 gcloud
On the GCP console, before you create the VM, you can get the equivalent command line
as gcloud
one:
We can just run the command to create:
$ gcloud compute instances create pkslow-vm \
--project=pkslow \
--zone=us-west1-a \
--machine-type=e2-micro \
--network-interface=network-tier=PREMIUM,subnet=default \
--maintenance-policy=MIGRATE \
[email protected] \
--scopes=https://www.googleapis.com/auth/cloud-platform \
--tags=http-server,https-server \
--create-disk=auto-delete=yes,boot=yes,device-name=instance-1,image=projects/centos-cloud/global/images/centos-8-v20211105,mode=rw,size=20,type=projects/pkslow/zones/us-west1-a/diskTypes/pd-standard \
--no-shielded-secure-boot \
--shielded-vtpm \
--shielded-integrity-monitoring \
--reservation-affinity=any
Created [https://www.googleapis.com/compute/v1/projects/pkslow/zones/us-west1-a/instances/pkslow-vm].
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
pkslow-vm us-west1-a e2-micro 10.138.0.5 34.145.124.xxx RUNNING
10.138.0.5 34.145.124.xxx RUNNING
Check the instance:
$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
pkslow-vm us-west1-a e2-micro
4 Terraform
We can use the Terraform to manage Infrastucture:
provider "google" {
project = "pkslow"
}
resource "google_compute_instance" "test" {
name = "pkslow-test"
machine_type = "e2-micro"
zone = "us-west1-a"
tags = ["http-server", "https-server"]
boot_disk {
initialize_params {
image = "projects/centos-cloud/global/images/centos-8-v20211105"
}
}
network_interface {
network = "default"
access_config {
// Ephemeral public IP
}
}
metadata = {
foo = "bar"
}
metadata_startup_script = "echo hi > /test.txt"
service_account {
# Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
email = "[email protected]"
scopes = ["cloud-platform"]
}
}
$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
pkslow-test us-west1-a e2-micro 10.138.0.6 34.83.138.xxx RUNNING
pkslow-vm us-west1-a e2-micro 10.138.0.5 34.145.124.xxx RUNNING
5 Code
Code on GitHub: https://github.com/LarryDpk/pkslow-samples
Reference:
Terraform GCP Compute Instance
欢迎关注微信公众号<南瓜慢说>,将持续为你更新...
推荐阅读:
如何制定切实可行的计划并好好执行
容器技术(Docker-Kubernetes)
SpringBoot-Cloud相关
Https专题
- 本文作者: 南瓜慢说
- 本文链接: https://www.pkslow.com/archives/create-gcp-gce-en
- 版权声明: 本博客所有文章除特别声明外,不可转载!
Recommend
-
39
Scripting with gcloud: a beginner’s guide to automating GCP tasks 2018-10-27adminGoogleCloud
-
14
Google Cloud Functions Tutorial : Using gcloud ToolThis is part of a Google Cloud Functions Tutorial Series. Check out th...
-
13
技术之前,先读诗书:焦土已经三月火,残花犹发万年枝。 如何在GCE访问GKE中的TCP服务
-
6
技术之前,先读诗书:低声问向谁行宿,城上已三更。 gcloud Config 初始化配置: gcloud init 列出配置信息: g...
-
4
Deploying application onto GCE using codeship Reading Time: 3 minutes Codeship Basic uses fast, performant VMs with preins...
-
26
All Posts GCloud 命令行工具常用操作 @SOLUTION· 2021-08-24 23:15 · 14 min read 安装 GCloud 工具下载安装包:
-
13
1 Introduction Cloud SQL helps to manage RDB on GCP for us. There are 3 ways to create the database: (1) Create on Console (2) Create with gcloud (3) Create with Terraform For GCP...
-
1
New regions supported in GCE Written by Lovisa Johansson 2019-05-20 Support has been added for some new r...
-
9
如果要选择GCP为云平台,则经常需要创建GCE(Google Compute Engine),有以下几种方式: (1) 在浏览器创建 (2) 命令 gcloud (3) Terraform 在开始之前,可以查看:《
-
11
Cloud SQL 是GCP上的关系型数据库,常用的有三种方式来创建: (1) 界面操作 (2) 命令行 gcloud (3) Terraform 在开始之前,可以查看:《初始化...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK