my first week with gcp
This blog article is my first one related to GCP (Google Cloud Platform). I just started as Cloud Customer Engineer at Google this week. So here are some learnings I would like to write down and share.
The onboarding process is really inspiring and well structured, driven by the collaboration and a learning experience led by practicing. Among different trainings and tools received, I got a great experience with G Suite and my Pixelbook, that’s concretely my very first time with them. Really impressive productivity!
Simplicity, Security.
One setup on my Pixelbook I have done, is enabling the Linux feature on it. And from there, I was able to install tools I need locally: Docker, Kubernetes, Terraform, Slack, VS Code with the Cloud Code extension, etc. You could find more details about this setup with this blog article: Build a dev workflow with Cloud Code on a Pixelbook.
Among different internal trainings I’m having related to my role, I also took the opportunity to learn more about GCP (for the very first time too), by practicing. I indeed needed to run few CLI commands! ;)
To accomplish this I took the Google Cloud Essentials course on Qwiklabs:
- Compute Engine: Linux and Windows
- Impressive to see how fast it is to provision a VM!
- Cloud Shell
- Love the very productive
gcloud beta interactive
command!
- Love the very productive
- Kubernetes Engine
- Interestingly, one GKE cluster comes with Node auto-repair and Node auto-upgrade by default.
- Load Balancers
- This doc is a great resource to see your different options about Load Balancer on GCP.
The experience with Qwiklabs is awesome! I got step-by-step labs allowing me to do hands-on via the Google Cloud Console and via the Google Cloud Shell. Furthermore, the last exercise is a challenge, not step-by-step guided, making sure I’m able to do it by myself!
Here are few general resources I have captured to keep as references:
- Google Cloud Next OnAir 2020
- Here is very detailed description of this event: The Google Cloud Next OnAir Cheat Sheet
- GCP Blog
- GCP Docs
- GCP Pricing
- GCP Certifications
- GCP Locations
- Regions and Zones
- GCP CLI
Well, that’s really cool, but now let’s take one of my containerized app: myblog
and delpoy it on GCP! For that we will leverage 4 services in GCP:
- Google Artifact Registry
- Google Cloud Run, yep Cloud Run could run website too! ;)
- Google Cloud App Engine
- Google Kubernetes Engine
I’m running all the commands below since I have installed locally, like explained above, the gcloud
, Docker
and kubectl
CLIs. But you could also do this from within the Google Cloud Shell which has already the three of them installed too (yep, with a Docker daemon too to succesfully run all your docker
commands ;)).
# Clone the Git repo locally
git clone https://github.com/mathieu-benoit/myblog
git submodule init
git submodule update
cd myblog
# Setup the Project
gcloud init
gcloud config list
gcloud auth list
projectId=FIXME
projectName=FIXME
folderId=FIXME
gcloud projects create $projectId \
--folder $folderId \
--name $projectName
gcloud config set project $projectId
gcloud beta billing accounts list
billingAccountId=FIXME
gcloud beta billing projects link $projectId \
--billing-account $billingAccountId
# Build and Push the Container in GCR
gcloud services enable artifactregistry.googleapis.com
location=us-east4
registryName=containers
gcloud artifacts repositories create $registryName \
--location $location \
--repository-format docker
registryHostName=$location-docker.pkg.dev
gcloud auth configure-docker $registryHostName --quiet
imageName=$registryHostName/$projectId/$registryName/myblog:1
docker build -t $imageName .
docker push $imageName
# Check the image pushed
gcloud artifacts docker images list $imageName
From here, we could now deploy this container from Artifact Registry to any services capable of hosting a container and which has access to pull the image. By default, any GCP service in the GCR’s Project, has the proper access to do this. Now let’s deploy this container image in three different services: Cloud Run, App Engine and Kubernetes Engine.
# Deploy this container on Cloud Run (< 1min)
gcloud services enable run.googleapis.com
gcloud run deploy myblog \
--image $imageName \
--region us-east1 \
--platform managed \
--allow-unauthenticated
# Deploy this container on Google App Engine (~ 5min)
gcloud services enable appengineflex.googleapis.com
echo "runtime: custom" >> app.yaml
echo "env: flex" >> app.yaml
gcloud app deploy \
--image-url $imageName
# Deploy this container on GKE (~ 5min)
gcloud services enable container.googleapis.com
clusterName=mygkecluster
zone=us-east1-b
gcloud container clusters create $clusterName \
--zone $zone
gcloud container clusters get-credentials $clusterName \
--zone $zone
kubectl run myblog \
--image=$imageName \
--generator=run-pod/v1
kubectl expose pod myblog \
--type=LoadBalancer \
--port=8080 \
--target-port=8080
What a first week, really exciting! More learnings and blog articles related to GCP to come for sure! Stay tuned, cheers! ;)