gcloud komutu
Yardım ve açıklamalar burada
auth seçeneği
gcloud auth seçeneği yazısına taşıdım
compute firewall-rules
Örnek
Açıklaması şöyle
Whenever you create a new project in Google Cloud, you get the default virtual private cloud (VPC). The virtual machines (VMs) that will host my application instances will run within that VPC.I created a firewall rule to allow SSH, HTTP, and HTTPS traffic:The rule will apply to all the VMs labeled geo-messenger-instance.
Şöyle yaparız
gcloud compute --project=geo-distributed-messenger \ firewall-rules create geo-messenger-allowed-traffic \ --direction=INGRESS --priority=1000 --network=default \ --action=ALLOW --rules=tcp:22,tcp:80,tcp:443 \ --source-ranges=0.0.0.0/0 --target-tags=geo-messenger-instance
compute instances
create, delete, describe, list, start, stop seçenekleri kullanılabilir
create
Örnek
Şöyle yaparız
gcloud compute instances create test1 --zone= us-east1-c
Örnek
Elimizde start_single_app_instance.sh kodu olsun
#! /bin/bash while getopts n:z:a:c:u:p: flag do case "${flag}" in n) name=${OPTARG};; z) zone=${OPTARG};; a) port=${OPTARG};; c) url=${OPTARG};; u) user=${OPTARG};; p) pwd=${OPTARG};; esac done echo "Starting instance $name in zone $zone..." gcloud compute instances create $name \ --project=geo-distributed-messenger \ --machine-type=e2-small \ --boot-disk-type=pd-balanced --boot-disk-size=10GB \ --network=default --zone=$zone \ --image-family=ubuntu-1804-lts --image-project=ubuntu-os-cloud \ --tags=geo-messenger-instance, \ --metadata-from-file=startup-script=startup_script.sh, \ --metadata=PORT=$port,DB_URL=$url,DB_USER=$user,DB_PWD=$pwd if [ $? -eq 0 ]; then echo "Instance $name has been created!" echo "The will be started on port $port and connect to the database $url" echo "Use command below to check the progress: " echo " " echo " gcloud compute ssh $name --project=geo-distributed-messenger" echo " sudo journalctl -u google-startup-scripts.service -f" else echo FAIL
Söz dizimi şöyle
./start_single_app_instance.sh \ -n {INSTANCE_NAME} \ -z {CLOUD_ZONE_NAME} \ -a {APP_HTTP_PORT_NUMBER} \ -c "{DATABASE_CONNECTION_ENDPOINT}" \ -u {DATABASE_USER} \ -p {DATABASE_PWD}
west için şöyle yaparız
./start_single_app_instance.sh \ -n messenger-us-west-instance \ -z us-west2-a \ -a 80 \ -c "jdbc:postgresql://us-east1.my-instance-id.gcp.ybdb.io:5433/yugabyte?ssl=true&sslmode=require" \ -u my-user-name \ -p my-super-complex-password
east için şöyle yaparız
./start_single_app_instance.sh \ -n messenger-us-east-instance \ -z us-east4-a \ -a 80 \ -c "jdbc:postgresql://us-east1.my-instance-id.gcp.ybdb.io:5433/yugabyte?ssl=true&sslmode=require" \ -u my-user-name \ -p my-super-complex-password
central için şöyle yaparız
./start_single_app_instance.sh \ -n messenger-us-central-instance \ -z us-central1-a \ -a 80 \ -c "jdbc:postgresql://us-east1.my-instance-id.gcp.ybdb.io:5433/yugabyte?ssl=true&sslmode=require" \ -u my-user-name \ -p my-super-complex-password
config set
Örnek
Şöyle yaparız
gcloud config set compute/region europe-west gcloud config set compute/zone europe-west1-c
delete
Şöyle yaparız
gcloud compute instances delete test1
describe
Şöyle yaparız
$ gcloud compute instances describe rlwy-04-kkbrp-worker-a-bs5xt --zone us-central1-a cpuPlatform: Intel Haswell creationTimestamp: '2022-08-24T23:20:41.092-07:00' deletionProtection: false disks: - autoDelete: true boot: true deviceName: persistent-disk-0 diskSizeGb: '300' guestOsFeatures: - type: VIRTIO_SCSI_MULTIQUEUE - type: UEFI_COMPATIBLE index: 0 interface: SCSI kind: compute#attachedDisk licenses: - https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx mode: READ_WRITE source: https://www.googleapis.com/compute/v1/projects/... type: PERSISTENT - autoDelete: true boot: false deviceName: persistent-disk-1 diskSizeGb: '200' index: 1 interface: SCSI kind: compute#attachedDisk mode: READ_WRITE source: https://www.googleapis.com/compute/v1/projects/... type: PERSISTENT ...
list
Şöyle yaparız
gcloud compute instances list
stop
Instance'ları durdurmak için şöyle yaparız. Proje ismi atanıyor. Daha sonra compute/zone atanıyor. İsme göre filtreleniyor ve bunlar üzerinde dolaşılarak durduruluyorlar
gcloud config set project product-oce-private && \ gcloud config set compute/zone us-central1-a && \ gcloud compute instances list --filter="name~'rlwy-04-*'" | \ grep -v NAME | \ cut -d ' ' -f1 | \ while read line ; do \ echo $line ; gcloud compute instances stop $line; \ done
Instance'ları başlatmak için şöyle yaparız
gcloud config set project product-oce-private && \ gcloud config set compute/zone us-central1-a && \ gcloud compute instances list --filter="name~'rlwy-04-*'" | \ grep -v NAME | \ cut -d ' ' -f1 | \ while read line ; do \ echo $line ; gcloud compute instances start $line; \ done
Çıktısı şöyle
Updated property [core/project]. Updated property [compute/zone]. foo-04-7hdxf-master-0 Starting instance(s) foo-04-7hdxf-master-0... ..........................................................done. Updated [https://compute.googleapis.com/compute/v1/projects/product-foo-private/ zones/us-central1-a/instances/foo-04-7hdxf-master-0]. Instance internal IP is 172.18.16.173 foo-04-7hdxf-master-1 Starting instance(s) foo-04-7hdxf-master-1... ..................................done. Updated [https://compute.googleapis.com/compute/v1/projects/product-foo-private/ zones/us-central1-a/instances/foo-04-7hdxf-master-1]. Instance internal IP is 172.18.16.163 foo-04-7hdxf-master-2 Starting instance(s) foo-04-7hdxf-master-2... ...................................done. Updated [https://compute.googleapis.com/compute/v1/projects/product-foo-private/ zones/us-central1-a/instances/foo-04-7hdxf-master-2]. Instance internal IP is 172.18.16.204 foo-04-7hdxf-worker-a-277vt Starting instance(s) foo-04-7hdxf-worker-a-277vt... ...........................................done. Updated [https://compute.googleapis.com/compute/v1/projects/product-foo-private/ zones/us-central1-a/instances/foo-04-7hdxf-worker-a-277vt]. Instance internal IP is 172.18.16.226 foo-04-7hdxf-worker-a-2xzmg Starting instance(s) foo-04-7hdxf-worker-a-2xzmg... ............................done. ...
app
Örnek
Şöyle yaparız
#bölge seçilirgcloud app create#editor açarcloudshell workspace appengine-try-java#editor içindemvn appengine:rungcloud config set project myprojectmvn appengine:deploy
container clusters create
gcloud container clusters create seçeneği yazısına taşıdım
container fleet
container fleet yazısına taşıdım
container clusters get-credentials
Açıklaması şöyle. Böylece artık kubectl komutları ile cluster'a erişiriz
gcloud container clusters get-credentials updates a kubeconfig file with appropriate credentials and endpoint information to point kubectl at a specific cluster in Google Kubernetes Engine.
Söz dizimi şöyle. zone ismi olarak europe-west2, europe-west4 kullanılabilir
gcloud container clusters get-credentials <<your_kubernetes_cluster_name>> \ --zone=<<your_zone_name>> \ --project=<<your_gcp_project_id>>
Örnek
cluster'a login olmak için şöyle yaparız
gcloud auth activate-service-account --key-file=product.json gcloud container clusters get-credentials ${CLUSTER_NAME} --zone us-central1-a --project ${PROJECT_ID}
Örnek
cluster'a login olmak için şöyle yaparız
# Get the credentials gcloud container clusters get-credentials east-cluster --zone=us-east4-b gcloud container clusters get-credentials europe-cluster --zone=europe-west1-c gcloud container clusters get-credentials asia-cluster --zone=asia-south1-b
container/images
Örnek
Şöyle yaparız
gcloud container images list-tags gcr.io/PROJECT/myimage
Örnek
Belli bir tag'i aramak için şöyle yaparız
gcloud container images list-tags --project product-spanner --filter=tags:85.1.91-alpha16 --format=json gcr.io/product-spanner/oce/rlwy
Silmek için şöyle yaparız
gcloud container images delete gcr.io/product-spanner/oce/rlwy:85.1.91-alpha28
Örnek
Tüm tag'leri görmek için şöyle yaparız.
$ gcloud container images list-tags --project product-spanner gcr.io/product-spanner/oce/rlwy DIGEST TAGS TIMESTAMP f3b20a3c3cf8 85.1.91-alpha28 2022-08-12T07:55:36 aaa2ad58d288 85.1.91-alpha27 2022-07-30T15:27:52 67bb81211a3d 85.1.91-alpha26 2022-07-30T06:48:39
Şöyle yaparız. Burada aslında image üzerinde iki tane tag var.
$ gcloud container images list-tags --project product-spanner gcr.io/product-spanner/oce/oce-rlwy-gui DIGEST TAGS TIMESTAMP 11c28c119b15 9d9c3ac,v0.0.26 2022-08-17T12:33:14 9c6502979fd6 2022-08-12T07:26:56
Json olarak görmek için şöyle yaparız
$ gcloud container images list-tags --project product-spanner --format json gcr.io/product-spanner/oce/oce-rlwy-gui | more [ { "digest": "sha256:11c28c119b159ab25a8faa4a63566f7d143e76e69b1a5218aac0a51dd8d40772", "tags": [ "9d9c3ac", "v0.0.26" ], "timestamp": { "datetime": "2022-08-17 12:33:14+00:00", "day": 17, "fold": 0, "hour": 12, "microsecond": 0, "minute": 33, "month": 8, "second": 14, "year": 2022 } },
config set project
Örnek
Şöyle yaparız
$ gcloud auth login $ gcloud config set project <YOUR_GCP_PROJECT_HERE> $ gcloud auth application-default login
Örnek
Şöyle yaparız
#Storage bucket in GCS # Select GCP project $ gcloud config set project [project-name] # Create a GCS bucket $ gsutil mb -l us-central1 -b on gs://my-vitess-operator-backup-bucket Creating gs://my-vitess-operator-backup-bucket/... # Create a GCP service account $ gcloud iam service-accounts create my-backup-service-account Created service account [my-backup-service-account]. # Grant the service account access to the bucket gsutil iam ch $ gsutil iam ch serviceAccount:my-backup-service-account@planetscale-dev.iam.gserviceaccount.com:objectViewer,objectCreator,objectAdmin \ gs://my-vitess-operator-backup-bucket # Create and download a key for the service account $ gcloud iam service-accounts keys create ~/gcs_key.json --iam-account my-backup-service-account@planetscale-dev.iam.gserviceaccount.com created key [ccd65b5a198298f9ca07ee6ab901a2492ea142c7] of type [json] as [/Users/askdba/gcs_key.json] for [my-backup-service-account@planetscale-dev.iam.gserviceaccount.com] # Upload the service account key as a k8s Secret $ kubectl create secret generic gcs-auth --from-file=gcs_key.json="$HOME/gcs_key.json" secret/gcs-auth created # Delete the local copy $ rm ~/gcs_key.json
projects
gcloud projects seçeneği yazısına taşıdım
services yazısına taşıdım
Hiç yorum yok:
Yorum Gönder