Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save SC0nner/09cf3749b4b45371c3fad7b44dd49d48 to your computer and use it in GitHub Desktop.

Select an option

Save SC0nner/09cf3749b4b45371c3fad7b44dd49d48 to your computer and use it in GitHub Desktop.
Tips and tricks related with Google Compute engine

Creating a Persistent Disk

Create a new instance
gcloud compute instances create gcelab --zone us-central1-c
Create a new persistent disk
gcloud compute disks create mydisk --size=200GB \
--zone us-central1-c
Attaching a disk
gcloud compute instances attach-disk gcelab --disk mydisk --zone us-central1-c
Finding the persistent disk in the virtual machine
gcloud compute ssh gcelab --zone us-central1-c
Formatting and mounting the persistent disk
# Step 1
sudo mkdir /mnt/mydisk

# Step 2
sudo mkfs.ext4 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/disk/by-id/scsi-0Google_PersistentDisk_persistent-disk-1

# Step 3
sudo mount -o discard,defaults /dev/disk/by-id/scsi-0Google_PersistentDisk_persistent-disk-1 /mnt/mydisk

Docker

Create a Docker container image
docker build -t gcr.io/PROJECT_ID/hello-node:v1 .
docker run -d -p 8080:8080 gcr.io/PROJECT_ID/hello-node:v1
gcloud docker -- push gcr.io/PROJECT_ID/hello-node:v1

Kubernates

Create your cluster
gcloud config set project PROJECT_ID
gcloud container clusters create hello-world \
                --num-nodes 2 \
                --machine-type n1-standard-1 \
                --zone us-central1-a
Create your pod
kubectl run hello-node \
    --image=gcr.io/PROJECT_ID/hello-node:v1 \
    --port=8080
# To view the deployment, run:
kubectl get deployments
# To view the pod created by the deployment, run:
kubectl get pods
Kubernates basic commands
kubectl cluster-info
kubectl config view
kubectl get events
kubectl logs <pod-name>
Allow external traffic
kubectl expose deployment hello-node --type="LoadBalancer"
# To find the publicly-accessible IP address of the service, request kubectl to list all the cluster services:
kubectl get services
Scale up your service
kubectl scale deployment hello-node --replicas=4
Roll out an upgrade to your service
kubectl edit deployment hello-node

Storage

In Cloud Shell, run the following to move file yob2014.txt into your bucket. Replace <your_bucket> with the name of the bucket you just created:

gsutil cp yob2014.txt gs://<your_bucket>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment