gcloud Commands Flashcards
What is the basic command syntax?
Format: gcloud [GROUP] [GROUP] [COMMAND] –arguments Example: gcloud compute instances create instance-1 –zone us-central1-a
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)
gcloud projects create black-butterfly-4450 \
–name black-butterfly \
–set-as-default
What are the different groups of commands for the group argument?
gcloud “group” command arg
config
iam
auth
storage
kubernetes
compute instances
Compute networks
components
deployments - Deployment Manager
Set a default project
black-butterfly-4450
gcloud config set core/project black-butterfly-4450
You must specify the project ID (globally unique) not the project name.
Set a default compute region and zone
gcloud config set compute/region europe-west6
gcloud config set compute/zone europe-west6-a
Disable interactive prompts
gcloud config set core/disable_prompts 1
Disables all interactive prompts, for example, when deleting resources.
List the current CLI configuration
gcloud config list
Create a VPC network without any subnets
gcloud compute networks create my-vpc –subnet-mode custom
A VPC network is is global. Subnets are regional.
Manually create a subnet
gcloud compute networks subnets create my-subnet-1 \
–network my-vpc \
–range 10.240.0.0/24
Create a VPC network with automatic subnets
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).
Get all subnets of a VPC network
gcloud compute networks subnets list –filter=”network:my-vpc”
What are gcloud CLI properties?
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.
What is a gcloud configuration?
A configuration is a set of gcloud CLI properties.
A configuration works like a profile.
What is the gcloud default configuration?
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 can you work with multiple projects or authorization accounts?
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 can you control prompting?
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.
What is a gcloud CLI Component?
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.
What can you do with gcloud CLI Components?
Managing gcloud CLI components
You can list, install, update, and remove gcloud CLI components to suit your needs.
How can your personalize your gcloud CLI environment?
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
To see a list of components that are available and currently installed, run?
gcloud components list
To install a component at the current version of your gcloud CLI installation, run?
run gcloud components install:
gcloud components install [COMPONENT-ID]
Grant and revoke authorization to the gcloud CLI and manage credentials use these commands?
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.
Configuring Identity and Access Management (IAM) preferences and service accounts.
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.
What commands would you use to manage docker containers and GKE?
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.
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.
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.
Get all subnets of a VPC network, “my-vpc”
gcloud compute networks subnets list –filter=”network:my-vpc”
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
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
Create a compute instance with a specific OS image
gcloud compute instances create i1 \
–image-family ubuntu-1804-lts \
–image-project ubuntu-os-cloud
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)
List all available images (including projects and families) with:
gcloud compute images list
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
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
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.
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]
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
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
Define a property (like compute/zone) for current configuration
gcloud config set
Fetch value of a gcloud CLI property
gcloud config get value
Display all the properties for the current configuration
gcloud config list
Create a new named configuration
gcloud config configurations create