Google Cloud Platform SDK

Install Cloud SDK

https://cloud.google.com/sdk/downloads

Unzip the source file

Note that the folder is you installation folder, select your preferred location

sh ./install.sh

And let the script do the auto-completion for you.

Log in

gcloud auth login

Set application default credentials

gcloud auth application-default
#Credentials saved to file:
#[/Users/spencer/.config/gcloud/application_default_credentials.json]
#These credentials will be used by any library that requests
#Application Default Credentials.

Create a configuration (repeat if you need more)

gcloud init

To show the list of configurations

gcloud config configurations list

To activate a different config

gcloud config configurations activate [config name]

Google Compute

Create compute instance (google virtual machine)

https://cloud.google.com/sdk/gcloud/reference/

Create an instance from standard machine types (image type)

gcloud compute instances create --machine-type n1-standard-2 my-instance

Check available machine types

gcloud compute machine-types
#NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP #EXTERNAL_IP STATUS
#my-instance europe-west1-b n1-standard-2 10.132.0.2 104.155.70.152 RUNNING

Detele an instance

gcloud compute instances delete my-instance

Create a customized instance

gcloud compute instances create --custom-cpu 4 --custom-memory 4GB my-instance
# NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
#my-instance europe-west1-b custom (4 vCPU, 4.00 GiB) 10.132.0.2 130.211.88.0 RUNNING

Connet to an instance

gcloud compute ssh my-instance

Copy files from local to instance

gcloud compute scp myfile.txt my-instance:~/remote-dir
# conversely, you can copy from instance to local

Google Container

Create cluster for container (using kurbernatetes)

gcloud container clusters create my-cluster --machine-type n1-standard-2 --num-nodes 4

Build a Docker image locally

docker build -f Dockerfile .
#docker run -t ubuntu

Upload a Docker image to Container Registry (so that Container Engine can use)

https://cloud.google.com/container-registry/docs/pushing-and-pulling

 
The registry should be formatted as (like you do with Dockerhub)
[HOSTNAME]/[YOUR-PROJECT-ID]/[IMAGE]
HOSTNAME can be one of
– us.gcr.io
– eu.gcr.io
– asia.gcr.io
– gcr.io

For example:
Image name: ubuntu
Register: gcr.io/my-project/ubuntu

docker tag ubuntu specerimp/my-project/ubuntu
gcloud docker -- push spencer/my-project/ubuntu

Check the images on Container Registry

gcloud container images list

Use Kubernetes to create pod/container/ from registry on Google Cloud
https://cloud.google.com/container-engine/docs/quickstart

You need to get auth credentials and create a cluster before creating a pod

gcloud concainer clusters get-credentials my-cluster
gcloud container clusters create my-cluster
kubectl run my-pod --image=gcr.io/my-project/ubuntu 
#deployment "my-pod" created

Check pods on the cluster

kubectl get pods
#NAME READY STATUS RESTARTS AGE
#my-pod-2776559432-kfhj3 0/1 Completed 3 58s

Expose/deploy the container to cluster (create a service)
Note that you HAVE to specify –port either in creating a pod or deployment

kubectl expose deployment my-pod

Delete a service and cluster to remove a deployment

kubectl delete services my-pod

https://cloud.google.com/container-engine/docs/quickstart

Advertisements