gcloud Commands Flashcards

1
Q

What is the basic command syntax?

A

Format: gcloud [GROUP] [GROUP] [COMMAND] –arguments Example: gcloud compute instances create instance-1 –zone us-central1-a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Create a new project and set it as the default

black-butterfly-4450 is the project ID (must be globally unique)
black-butterfly is the project name (must be unique in your account)

A

gcloud projects create black-butterfly-4450 \
–name black-butterfly \
–set-as-default

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the different groups of commands for the group argument?
gcloud “group” command arg

A

config
iam
auth
storage
kubernetes
compute instances
Compute networks
components
deployments - Deployment Manager

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Set a default project
black-butterfly-4450

A

gcloud config set core/project black-butterfly-4450
You must specify the project ID (globally unique) not the project name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Set a default compute region and zone

A

gcloud config set compute/region europe-west6
gcloud config set compute/zone europe-west6-a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Disable interactive prompts

A

gcloud config set core/disable_prompts 1
Disables all interactive prompts, for example, when deleting resources.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

List the current CLI configuration

A

gcloud config list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Create a VPC network without any subnets

A

gcloud compute networks create my-vpc –subnet-mode custom
A VPC network is is global. Subnets are regional.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Manually create a subnet

A

gcloud compute networks subnets create my-subnet-1 \
–network my-vpc \
–range 10.240.0.0/24

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Create a VPC network with automatic subnets

A

gcloud compute networks create my-vpc
Automatically creates a subnet in every region.

Subnets have a */20 CIDR range (e.g. 10.128.0.0/20).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Get all subnets of a VPC network

A

gcloud compute networks subnets list –filter=”network:my-vpc”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are gcloud CLI properties?

A

The gcloud CLI properties are settings that affect the behavior of the gcloud CLI tools. Some of these properties can be set by either global or command options—in which case, the value set by the option takes precedence.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a gcloud configuration?

A

A configuration is a set of gcloud CLI properties.
A configuration works like a profile.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the gcloud default configuration?

A

When you start using the gcloud CLI, you’ll work with a single configuration named default and you can set properties by running gcloud init or gcloud config set. This single default configuration is suitable for most use cases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can you work with multiple projects or authorization accounts?

A

You can set up multiple configurations with gcloud config configurations create and switch among the configurations. Within a configuration, you can customize properties. For example, to set your project within an active configuration use the project property:

gcloud config set project <project-id></project-id>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How can you control prompting?

A

To protect against unintended destructive actions, the gcloud CLI confirms your intentions before executing commands such as gcloud projects delete.

You might be prompted when additional information is needed. For example you will be asked to choose a zone when you create a Compute Engine virtual machine instance using gcloud compute instances create test-instance.

To disable prompting, use the –quiet option.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a gcloud CLI Component?

A

Components are the installable parts of the Google Cloud CLI. A component can be a command-line tool (gcloud, bq, and gsutil), a set of gcloud CLI commands at the Alpha or Beta release levels, or a package that contains dependencies used by a tool in the gcloud CLI.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What can you do with gcloud CLI Components?

A

Managing gcloud CLI components
You can list, install, update, and remove gcloud CLI components to suit your needs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How can your personalize your gcloud CLI environment?

A

personalize your configuration with properties.

gcloud config set: Define a property (like compute/zone) for the current configuration.
gcloud config get-value: Fetch the value of a gcloud CLI property.
gcloud config list: Display all the properties for the current configuration.
gcloud config configurations create: Create a new named configuration.
gcloud config configurations list: Display a list of all available configurations.
gcloud config configurations activate: Switch to an existing named configuration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

To see a list of components that are available and currently installed, run?

A

gcloud components list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

To install a component at the current version of your gcloud CLI installation, run?

A

run gcloud components install:
gcloud components install [COMPONENT-ID]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Grant and revoke authorization to the gcloud CLI and manage credentials use these commands?

A

gcloud auth login: Authorize Google Cloud access for the gcloud CLI with Google Cloud user credentials and set the current account as active.
gcloud auth activate-service-account: Authorize Google Cloud access similar to gcloud auth login but with service account credentials.
gcloud auth application-default: Manage your Application Default Credentials (ADC) for Cloud Client Libraries.
gcloud auth list: List all credentialed accounts.
gcloud auth print-access-token: Display the current account’s access token.
gcloud auth revoke: Remove access credentials for an account.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Configuring Identity and Access Management (IAM) preferences and service accounts.

A

gcloud iam list-grantable-roles: List IAM grantable roles for a resource.
gcloud iam roles create: Create a custom role for a project or org.
gcloud iam service-accounts create: Create a service account for a project.
gcloud iam service-accounts add-iam-policy-binding: Add an IAM policy binding to a service account.
gcloud iam service-accounts set-iam-policy-binding: Replace existing IAM policy binding.
gcloud iam service-accounts keys list: List a service account’s keys.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What commands would you use to manage docker containers and GKE?

A

gcloud auth configure-docker: Register the gcloud CLI as a Docker credential helper.
gcloud container clusters create: Create a cluster to run GKE containers.
gcloud container clusters list: List clusters for running GKE containers.
gcloud container clusters get-credentials: Update kubeconfig to get kubectl to use a GKE cluster.
gcloud container images list-tags: List tag and digest metadata for a container image.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What commands would you use to create, run, and manage VMs on Google Cloud infrastructure?
gcloud compute zones list: List Compute Engine zones. gcloud compute instances create: Create a VM instance. gcloud compute instances describe: Display a VM instance's details. gcloud compute instances list: List all VM instances in a project. gcloud compute disks snapshot: Create snapshot of persistent disks. gcloud compute snapshots describe: Display a snapshot's details. gcloud compute snapshots delete: Delete a snapshot. gcloud compute ssh: Connect to a VM instance by using SSH.
26
Serverless & App Engine Build highly scalable applications on a fully managed serverless platform
gcloud app deploy: Deploy your app's code and configuration to the App Engine server. gcloud app versions list: List all versions of all services deployed to the App Engine server. gcloud app browse: Open the current app in a web browser. gcloud app create: Create an App Engine app within your current project. gcloud app logs read: Display the latest App Engine app logs.
27
Get all subnets of a VPC network, "my-vpc"
gcloud compute networks subnets list --filter="network:my-vpc"
28
Create a compute instance with a specific machine type, n1-standard-2
gcloud compute instances create i1 --machine-type=n1-standard-2 👉 Machine types 👈 Default machine type is n1-standard-1 (1 CPU, 3.75 GB RAM) Instance name argument can be repeated to create multiple instances
29
Create a compute instance in a specific VPC network and subnet
gcloud compute instances create i1 \ --network my-vpc \ --subnet my-subnet-1 Default VPC network is default If --network is set to a VPC network with “custom” subnet mode, then --subnet must also be specified Instance name argument can be repeated to create multiple instances
30
Create a compute instance with a specific OS image
gcloud compute instances create i1 \ --image-family ubuntu-1804-lts \ --image-project ubuntu-os-cloud
31
How does gcloud compute instance handle images?
👉 Images 👈 Default image family is debian-9 User either --image-family (uses latest image of this family) or --image (a concrete image) --image-project serves as a namespace for --image and --image-family(may have multiple images/image families with same name in multiple projects)
32
List all available images (including projects and families) with:
gcloud compute images list
33
Get the names of all compute instances
gcloud compute instances list --format="value(name)" 👉 Format syntax 👈 Can be used, for example, for deleting all existing compute instances: gcloud compute instances delete \ $(gcloud compute instances list --format="value(na
34
Allow ingress traffic to a VPC network
gcloud compute firewall-rules create my-vpc-allow-ssh-icmp \ --network my-vpc \ --allow tcp:22,icmp \ --source-ranges 0.0.0.0/0 0.0.0.0/0 is the default for --source-ranges and could be omitted. This allows incoming ICMP and SSH (TCP port 22) traffic to any instances in the VPC network from any source (e.g. from the public Internet). After creating this firewall rule, you’re able to: Ping instances in the VPC network: ping EXTERNAL_IP SSH to instances in the VPC network: gcloud compute ssh i1
35
Create a regional static IP address
gcloud compute addresses create addr-1 --region=europe-west6 Regional IP addresses an be attached to compute instances, regional load balancers, etc. in the same region as the IP address. The name argument can be repeated to create multiple addresses One of --global or --region must be specified.
36
What is a standard grouping for gcloud commands?
gcloud GROUP | COMMAND [--account=ACCOUNT] [--billing-project=BILLING_PROJECT] [--configuration=CONFIGURATION] [--flags-file=YAML_FILE] [--flatten=[KEY,…]] [--format=FORMAT] [--help] [--project=PROJECT_ID] [--quiet, -q]
37
What are some gcloud flags for a command?
Some flags are available throughout the gcloud experience, like: --project If using a project other than the current one --quiet Disable interactive prompts (and apply default values for inputs) --verbosity Can set verbosity levels at , , , , , debug info warning error critical none --version Display gcloud version information (only available at the global level) --format Set output format as , , , , , , , , , , , , , , , or . conf
38
Most gcloud instances follow what format?
gcloud component entity operation positional args flags Where: Component refers to different Google Cloud services Entity refers to the plural form of an element or collection of elements under a component Operation refers to the imperative verb form of the operation to be performed on the entity Positional args refer to the required, order-specific arguments needed to execute the command Flags refer to the additional arguments, --flag-name(=value) passed in to the command after positional args disks firewalls images instances regions , , , , , for zones compute
39
Define a property (like compute/zone) for current configuration
gcloud config set
40
Fetch value of a gcloud CLI property
gcloud config get value
41
Display all the properties for the current configuration
gcloud config list
42
Create a new named configuration
gcloud config configurations create
43
Authorize access for gcloud with Google user credentials and set current account as active
gcloud auth login
44
Like gcloud auth login but with service account credentials
gcloud auth activate-service-account
45
List all credentialed accounts
gcloud auth list
46
Display the current account’s access token
gcloud auth print-access-token
47
Remove access credentials for an account
gcloud auth revoke
48
Display metadata for a project (including its ID)
gcloud projects describe
49
Add an IAM policy binding to a project
gcloud projects add-iam-policy-binding
50
What is the difference between flags and arguments?
Arguments can be , which are set after command name and must respect the order of positional args or , which are set after positional args where the order of flags doesn’t matter. positional args flags A flag is either a (--foo=bar) or (--force/no force). Additionally, flags can either be force or optional When optional, the default value is used if the flag isn’t defined.
51
gcloud auth login
Authorize access for gcloud with Google user credentials and set current account as active
52
Like gcloud auth login but with service account credentials gcloud auth list
gcloud auth activate-service-account
53
List all credentialed accounts
gcloud auth list
54
Display the current account’s access token
gcloud auth print-access-token
55
Remove access credentials for an account
gcloud auth revoke
56
Display metadata for a project (including its ID)
gcloud projects describe
57
Add an IAM policy binding to a project
gcloud projects add-iam-policy-binding
58
Register gcloud as a Docker credential helper
gcloud auth configure-docker
59
Create a cluster to run GKE containers
gcloud container clusters create
60
List clusters to run GKE containers
gcloud container clusters list
61
Update kubeconfig to get kubectl to use a GKE cluster
gcloud container clusters get-credentials
62
List tag and digest metadata for a container image
gcloud container images list-tags
63
List IAM grantable roles for a resource
gcloud iam list-grantable-roles
64
Create a custom role for a project or org
gcloud iam roles create
65
Create a service account for a project
gcloud iam service-accounts create
66
List a service account’s keys
gcloud iam service-accounts keys list
67
Add an IAM policy to a service account
gcloud iam service-accounts add-iam-policy-binding
68
Replace existing IAM policy
gcloud iam service-accounts set-iam-policy
69
List Compute Engine zones
gcloud compute zones list
70
Display a virtual machine (VM) instance’s details
gcloud compute instances describe
71
gcloud compute instances list
List all VM instances in a project
72
Create snapshot of persistent disks
gcloud compute disks snapshot
73
Display a specified snapshot’s details
gcloud compute snapshots describe
74
Delete a snapshot
gcloud compute snapshots delete
75
Connect to a VM instance by using SSH
gcloud compute ssh
76
Deploy your app’s code and configuration to App Engine server
gcloud app deploy
77
List all versions of all services deployed to the App Engine server
gcloud app versions list
78
Open the current app in a web browser
gcloud app browse
79
Create an App Engine app within your current project
gcloud app create
80
Display the latest App Engine app logs
gcloud app logs read
81
Show the organization?
gcloud organizations list
82
What are config command group for in gcloud?
view and edit Google Cloud CLI properties SYNOPSIS gcloud config GROUP | COMMAND [GCLOUD_WIDE_FLAG …] DESCRIPTION The gcloud config command group lets you set, view and unset properties used by Google Cloud CLI. A configuration is a set of properties that govern the behavior of gcloud and other Google Cloud CLI tools. The initial default configuration is set when gcloud init is run. You can create additional named configurations using gcloud init or gcloud config configurations create.
83
What are the available gcloud config cli commands?
COMMAND is one of the following: get Print the value of a Google Cloud CLI property. list List Google Cloud CLI properties for the currently active configuration. set Set a Google Cloud CLI property. unset Unset a Google Cloud CLI property.
84
get project roles
gcloud projects get-iam-policy
85
copy roles across org and projects
gcloud iam roles copy
86
List all buckets and files
gsutil ls, gsutil ls -lh gs://
87
Create bucket
gsutil mb gs://
88
Download file
gsutil cp gs:////app.txt
89
Upload file
gsutil cp gs:////
90
Delete file
gsutil rm gs:///
91
Move file gsutil
mv gs:////
92
List all networks
gcloud compute networks list
93
Detail of one network
gcloud compute networks describe --format json
94
How to create a network
gcloud compute networks create
95
Create subnet
gcloud compute networks subnets create subnet1 --network subnet-1 --range 10.0.0.0/24
96
List all firewall rules
gcloud compute firewall-rules list
97
List all forwarding rules
gcloud compute forwarding-rules list
98
Create a signed URL for downloading an object valid for 10 minutes?
gsutil signurl -d 10m gs:///
99
Create a signed URL, valid for one hour, for uploading a plain text file via HTTP PUT?
gsutil signurl -m PUT -d 1h -c text/plain \ gs:///
100
List all forwarding rules
gcloud compute forwarding-rules list
101
To create a new named configuration, run:
gcloud config configurations create my-config
102
gcloud compute groups?
instances networks disks snapshots
103
gcloud command groups for iam
roles service-accounts
104
What commands are there to personalize the environment for gcloud?
105
change the machine type of an instance?
gcloud compute instances set-machine-type INSTANCE_NAME [--machine-type=MACHINE_TYPE] [--zone=ZONE] [--custom-cpu=CUSTOM_CPU --custom-memory=CUSTOM_MEMORY : --custom-extensions --custom-vm-type=CUSTOM_VM_TYPE] [GCLOUD_WIDE_FLAG …] DESCRIPTION gcloud compute instances set-machine-type lets you change the machine type of a virtual machine in the TERMINATED state (that is, a virtual machine instance that has been stopped). For example, the following command would create an instance running an N1 machine type with 4 vCPUs and 5 GB of total memory: gcloud compute instances create example-instance \ --custom-cpu=4 --custom-memory=5 For N2 machine types, use the gcloud compute instances create command and include one of the following options: The --custom-cpu, --custom-memory, and --custom-vm-type flags. The --machine-type=n2-custom-NUMBER_OF_CPUS-NUMBER_OF_MB flag. When using the --custom-memory flag, specify the total amount of memory in GB or in MB. The property must be an integer, so if you want to specify increments of 0.25 GB for memory, convert that value to MB instead. To specify an incremental value, such as 2.5 GB of memory, convert the value to MB and supply the value followed by the MB suffix. The following example creates an instance running an N2 machine type: gcloud compute instances create example-instance \ --custom-cpu=6 --custom-memory=3072MB --custom-vm-type=n2 Alternatively, you can specify a custom machine type using the following format: gcloud compute instances create example-instance \ --machine-type n2-custom-NUMBER_OF_CPUS-NUMBER_OF_MB Replace the following: NUMBER_OF_CPUS: The number of CPUs you want. NUMBER_OF_MB: The amount of memory, in MB. For example: gcloud compute instances create example-instance --machine-type=n2-custom-6-3072