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.