gcloud Commands Flashcards

You may prefer our related Brainscape-certified 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
Q

What commands would you use to create, run, and manage VMs on Google Cloud infrastructure?

A

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.

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

Serverless & App Engine Build highly scalable applications on a fully managed serverless platform

A

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.

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

Get all subnets of a VPC network, “my-vpc”

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
28
Q

Create a compute instance with a specific machine type, n1-standard-2

A

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

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

Create a compute instance in a specific VPC network and subnet

A

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

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

Create a compute instance with a specific OS image

A

gcloud compute instances create i1 \
–image-family ubuntu-1804-lts \
–image-project ubuntu-os-cloud

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

How does gcloud compute instance handle images?

A

👉 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)

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

List all available images (including projects and families) with:

A

gcloud compute images list

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

Get the names of all compute instances

A

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

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

Allow ingress traffic to a VPC network

A

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

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

Create a regional static IP address

A

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.

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

What is a standard grouping for gcloud commands?

A

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]

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

What are some gcloud flags for a command?

A

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

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

Most gcloud instances follow what format?

A

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

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

Define a property (like compute/zone) for current configuration

A

gcloud config set

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

Fetch value of a gcloud CLI property

A

gcloud config get value

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

Display all the properties for the current configuration

A

gcloud config list

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

Create a new named configuration

A

gcloud config configurations create

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

Authorize access for gcloud with Google user credentials and set current account as active

A

gcloud auth login

44
Q

Like gcloud auth login but with service account credentials

A

gcloud auth activate-service-account

45
Q

List all credentialed accounts

A

gcloud auth list

46
Q

Display the current account’s access token

A

gcloud auth print-access-token

47
Q

Remove access credentials for an account

A

gcloud auth revoke

48
Q

Display metadata for a project (including its ID)

A

gcloud projects describe

49
Q

Add an IAM policy binding to a project

A

gcloud projects add-iam-policy-binding

50
Q

What is the difference between flags and arguments?

A

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
Q

gcloud auth login

A

Authorize access for gcloud with Google user credentials and set current account as active

52
Q

Like gcloud auth login but with service account credentials
gcloud auth list

A

gcloud auth activate-service-account

53
Q

List all credentialed accounts

A

gcloud auth list

54
Q

Display the current account’s access token

A

gcloud auth print-access-token

55
Q

Remove access credentials for an account

A

gcloud auth revoke

56
Q

Display metadata for a project (including its ID)

A

gcloud projects describe

57
Q

Add an IAM policy binding to a project

A

gcloud projects add-iam-policy-binding

58
Q

Register gcloud as a Docker credential helper

A

gcloud auth configure-docker

59
Q

Create a cluster to run GKE containers

A

gcloud container clusters create

60
Q

List clusters to run GKE containers

A

gcloud container clusters list

61
Q

Update kubeconfig to get kubectl to use a GKE cluster

A

gcloud container clusters
get-credentials

62
Q

List tag and digest metadata for a container image

A

gcloud container images list-tags

63
Q

List IAM grantable roles for a resource

A

gcloud iam list-grantable-roles

64
Q

Create a custom role for a project or org

A

gcloud iam roles create

65
Q

Create a service account for a project

A

gcloud iam service-accounts create

66
Q

List a service account’s keys

A

gcloud iam service-accounts keys list

67
Q

Add an IAM policy to a service account

A

gcloud iam service-accounts
add-iam-policy-binding

68
Q

Replace existing IAM policy

A

gcloud iam service-accounts
set-iam-policy

69
Q

List Compute Engine zones

A

gcloud compute zones list

70
Q

Display a virtual machine (VM) instance’s details

A

gcloud compute instances describe

71
Q

gcloud compute instances list

A

List all VM instances in a project

72
Q

Create snapshot of persistent disks

A

gcloud compute disks snapshot

73
Q

Display a specified snapshot’s details

A

gcloud compute snapshots describe

74
Q

Delete a snapshot

A

gcloud compute snapshots delete

75
Q

Connect to a VM instance by using SSH

A

gcloud compute ssh

76
Q

Deploy your app’s code and configuration to App Engine server

A

gcloud app deploy

77
Q

List all versions of all services deployed to the App Engine
server

A

gcloud app versions list

78
Q

Open the current app in a web browser

A

gcloud app browse

79
Q

Create an App Engine app within your current project

A

gcloud app create

80
Q

Display the latest App Engine app logs

A

gcloud app logs read

81
Q

Show the organization?

A

gcloud organizations list

82
Q

What are config command group for in gcloud?

A

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
Q

What are the available gcloud config cli commands?

A

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
Q

get project roles

A

gcloud projects get-iam-policy

85
Q

copy roles across org and projects

A

gcloud iam roles copy

86
Q

List all buckets and files

A

gsutil ls, gsutil ls -lh gs://<bucket-name></bucket-name>

87
Q

Create bucket

A

gsutil mb gs://<bucket-name></bucket-name>

88
Q

Download file

A

gsutil cp gs://<bucket-name>/<dir-path>/app.txt</dir-path></bucket-name>

89
Q

Upload file

A

gsutil cp <filename> gs://<bucket-name>/<directory>/</directory></bucket-name></filename>

90
Q

Delete file

A

gsutil rm gs://<bucket-name>/<filepath></filepath></bucket-name>

91
Q

Move file gsutil

A

mv <src-filepath> gs://<bucket-name>/<directory>/<dest-filepath></dest-filepath></directory></bucket-name></src-filepath>

92
Q

List all networks

A

gcloud compute networks list

93
Q

Detail of one network

A

gcloud compute networks describe <network-name> --format json</network-name>

94
Q

How to create a network

A

gcloud compute networks create <network-name></network-name>

95
Q

Create subnet

A

gcloud compute networks subnets create subnet1 –network subnet-1 –range 10.0.0.0/24

96
Q

List all firewall rules

A

gcloud compute firewall-rules list

97
Q

List all forwarding rules

A

gcloud compute forwarding-rules list

98
Q

Create a signed URL for downloading an object valid for 10 minutes?

A

gsutil signurl -d 10m <private-key-file> gs://<bucket>/<object></object></bucket></private-key-file>

99
Q

Create a signed URL, valid for one hour, for uploading a plain text file via HTTP PUT?

A

gsutil signurl -m PUT -d 1h -c text/plain <private-key-file> \
gs://<bucket>/<obj></obj></bucket></private-key-file>

100
Q

List all forwarding rules

A

gcloud compute forwarding-rules list

101
Q

To create a new named configuration, run:

A

gcloud config configurations create my-config

102
Q

gcloud compute groups?

A

instances
networks
disks
snapshots

103
Q

gcloud command groups for iam

A

roles
service-accounts

104
Q

What commands are there to personalize the environment for gcloud?

A
105
Q

change the machine type of an instance?

A

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