Command list of GCP

Purpose
In this article, let me describe useful command for GCP.
You can pass GCP ACE exam by memorizing below commands.
Command list of GCP
Display subnet list in AAA region and BBB region.
> gcloud compute networks subnet list –filter=”region:(AAA BBB)”
Create Kubernetes cluster in AAA region with auto-scaling setting.
And, node number setting is below.
Initial node number: 30
Least node number: 15
Max node number: 50
> gcloud container cluster create test-cluster –num-nodes 30 –enable-autoscaling –min-nodes 15 –max-nodes 50 –zone AAA.

Execute script(test_script.sh) at the time of instance starting.
> gcloud compute instances create test-instance –metadata-from-file startup-script=scripts/test_script.sh
Access container shell
> kubectl exec -it my-pod –container my-app — /bin/bash

Set SQL injection countermeasure by applying Cloud Armor.
> gcloud compute security-policies rules create
with below parameter.
    — expression “evaluatePreconfiguredExpr(‘sqli-canary’)” — action deny-403
Display every GCE instances in zone AAA and zone BBB.
> gcloud compute instances list –filter=”zone:(AAA BBB)”
At the time of file upload to Cloud Storage, use encryption key of client stored in the on-premise environment.
> Designate “GSUtil: encryption_key=[YOUR_ENCRYPTION_KEY]” in the gsutil command.
How to access my-image.jpg in my-bucket of Cloud Storage.
> Access below URL.
https://storage.googleapis.com/my-bucket/my-image.jpg
Display Cloud SDK configuration list and enable other setting.
> gcloud config configurations list
> gcloud config configurations activate  XXXX
Create custom instance with 4 vCPU and 4GB memory.
> gcloud compute instances create my-custom-instance –custom-cpu 4 –custom-memory 4
Enable versioning function for the file stored in the Cloud Storage
> gsutil versioning set on gs://my-bucket
Display image list including “centos”
> gcloud compute images list –filter=name:ubuntu
Access a cluster created by other member
> gcloud container clusters get-credentials my-cluster
-> kubeconfig entry will be generated.Change default zone to AAA zone
> gcloud config set compute/zone AAA

 

Publicize your service.
Receive traffic with port number 8080 and publicize to external user with port 80 by Loadbalancer.
> kubectl expose deployment my-deployment –type LoadBalancer –port80 –target-port 8080

 

Expand IP range
> gcloud compute networks subnets expand-ip-range my-subnet –region AAA –prefix-length=XX

 

Deploy Web application to Kubernetes
> Execute docker build command to create container image.
And upload it to Container Registry.

 

Check the change contents in advance before updating your configuration with yaml file.
> gcloud deployment-manager deployments update my-config –config new-config.yaml –preview

 

Conducting test before migrating your application from App Engine standard environment to Flexible environment.
> set env: flex to app.yaml.
Execute gcloud app deploy command with –-no-promote option.
> After testing, migrate it by executing below command.
gcloud app versions migrate command.

 

Access relay server by SSH protocol
> gcloud compute ssh username@bastion-host

 

Create Kubernetes cluster in zone AAA with node number 6.
> gcloud container clusters create my-cluster –zone:AAA –num-nodes 6

 

Install App Engine Extended function for python2
> gcloud components install app-engine-python

 

Set auto-scaling with Average CPU usage 70% and max instance size 3.
> gcloud compute instance-groups managed set-autoscaling my-instance-group –max-num-replicas 3 –target-cpu-utilization 0.70

 

Deploy your application to production environment
> Execute gcloud app deploy command.

 

Publicize your file uploaded in the bucket by executing gsutil command tool.
> gsutil defacl set public-read gs://xxxx..com

 

Create a function on the Cloud Functions
> gcloud functions deploy

 

Access my project by Cloud SDK. JSON key file has already been created.
> gcloud auth activate-service-account my-service-account@my-project.xxxxx.com –key-file mykey.json –project test-project

Change account setting
> gcloud config configurations activate (Configuration name)
Allow users to upload PDF file within 2 hours
> gsutil signurl -m PUT -d 2h my-json-key.json gs://my-buckt/xxxx.pdf
Export data in BigQuery to Cloud Storage by CSV format
> bq extract my-table gs://my-bucket/xxxx.csv
Display deployment list
> gcloud deployment-manager deployments list –project my-project
Restore traffic to previous version.
> gcloud app services set-traffic my-service –splits <previous version> = 1
Calculate query execution of Bigquery
> Execute bq query –dry-run command.
Use Pricing Calculator and exchange byte expectation to cost.
Enable Google function by your application
> gcloud services enable cloudfunctions.googleapis.com
Create new role by copying existing role
> gcloud iam roles copy xxxx yyyy
Update deploy configuration without service stop
> gcloud deployment-manager deployments update –config new_config.yaml
Deploy java application by using App Engine
> Execute gcloud app deploy command by designating service component by app.yaml file.Display member and role list
> gcloud projects get-iam-policy my-project

 

That’s all for this topic. If you think this article is beneficial for me, I would be glad if you click below icon for my motivation.
ブログランキング・にほんブログ村へ

コメント