Google Cloud Platform
04 Oct 2019Regions and Zones 1
Region | Zones | Location |
---|---|---|
asia-east1 | a, b, c | Changhua County, Taiwan |
asia-east2 | a, b, c | Hong Kong |
asia-northeast1 | a, b, c | Tokyo, Japan |
asia-northeast2 | a, b, c | Osaka, Japan |
asia-south1 | a, b, c | Mumbai, India |
asia-southeast1 | a, b, c | Jurong West, Singapore |
australia-southeast1 | a, b, c | Sydney, Australia |
europe-north1 | a, b, c | Hamina, Finland |
europe-west1 | b, c, d | St. Ghislain, Belgium |
europe-west2 | a, b, c | London, England, UK |
europe-west3 | a, b, c | Frankfurt, Germany |
europe-west4 | a, b, c | Eemshaven, Netherlands |
europe-west6 | a, b, c | Zürich, Switzerland |
northamerica-northeast1 | a, b, c | Montréal, Québec, Canada |
southamerica-east1 | a, b, c | Osasco (São Paulo), Brazil |
us-central1 | a, b, c, f | Council Bluffs, Iowa, USA |
us-east1 | b, c, d | Moncks Corner, South Carolina, USA |
us-east4 | a, b, c | Ashburn, Northern Virginia, USA |
us-west1 | a, b, c | The Dalles, Oregon, USA |
us-west2 | a, b, c | Los Angeles, California, USA |
Setting a default compute zone
gcloud config set compute/zone us-central1-a
Set the default region:
gcloud config set compute/region us-central1
gsutil
command line
-[ ] TODO
VM instances
Help
gcloud compute instances create --help
Create
gcloud compute instances create gcelab2 --machine-type n1-standard-2 --zone us-central1-c
List
gcloud compute instances list
SSH access
gcloud compute ssh gcelab2 --zone us-central1-c
Template
Create a startup script to be used by every virtual machine instance.
cat << EOF > startup.sh
#! /bin/bash
apt-get update
apt-get install -y nginx
service nginx start
sed -i -- 's/nginx/Google Cloud Platform - '"\$HOSTNAME"'/' /var/www/html/index.nginx-debian.html
EOF
Create template
gcloud compute instance-templates create nginx-template \
--metadata-from-file startup-script=startup.sh
Target pool
gcloud compute target-pools create nginx-pool
Instance group
gcloud compute instance-groups managed create nginx-group \
--base-instance-name nginx \
--size 2 \
--template nginx-template \
--target-pool nginx-pool
Firewall rules
Create
gcloud compute firewall-rules create www-firewall --allow tcp:80
gcloud compute forwarding-rules create nginx-lb \
--region us-central1 \
--ports=80 \
--target-pool nginx-pool
List rules
gcloud compute forwarding-rules list
Kubernetes
Kubernetes Engine cluster
Create cluster
gcloud container clusters create [CLUSTER-NAME]
# like
gcloud container clusters create cluster1
List cluster
gcloud container clusters list
Get authentication credentials for the cluster
gcloud container clusters get-credentials [CLUSTER-NAME]
# like
gcloud container clusters get-credentials cluster1
Deploy application
Deploy
kubectl run hello-server --image=gcr.io/google-samples/hello-app:1.0 --port 8080
Expose your application to external traffic
kubectl expose deployment hello-server --type="LoadBalancer"
After deploy - get service detail
kubectl get service hello-server
Distroy cluster
gcloud container clusters delete cluster1
kubectl
check version
kubectl version
run instance
kubectl run nginx --image=nginx:1.10.0
get pots
kubectl get pods
expose deployment
kubectl expose deployment nginx --port 80 --type LoadBalancer
get services
kubectl get services
scale deployment
kubectl scale deployment nginx --replicas 3
–
App engine
deploy
gcloud app deploy ./index.yaml ./app.yaml
–
Storage
- to add
–
network
list
gcloud compute networks list
gcloud compute networks subnets list --sort-by=NETWORK
create
gcloud compute networks create privatenet --subnet-mode=custom
firlistewall rules
gcloud compute firewall-rules list --sort-by=NETWORK
–
Deployment Manager and Stackdriver
yaml
file
resources:
- name: my-vm
type: compute.v1.instance
properties:
zone: us-central1-a
machineType: zones/ZONE/machineTypes/n1-standard-1
metadata:
items:
- key: startup-script
value: "apt-get update"
disks:
- deviceName: boot
type: PERSISTENT
boot: true
autoDelete: true
initializeParams:
sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-9-stretch-v20180806
networkInterfaces:
- network: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/networks/default
accessConfigs:
- name: External NAT
type: ONE_TO_ONE_NAT
create deployment
gcloud deployment-manager deployments create my-first-depl --config mydeploy.yaml
update deployment
gcloud deployment-manager deployments update my-first-depl --config mydeploy.yaml