Skip to main content
WHAT WE ARE DOING

In this guide, I will walk you through the steps of installing the Google Cloud SDK on Ubuntu. Once the SDK is installed, we will use it to create a container cluster which will house our Kubernetes stack. From there we will use Kubernetes to create a pod and service.

ABOUT THE QUICKSTART

The quickstart will show you how to work with the Google Cloud Shell by deploying a Docker container image with a simple Node.js app.

SIGNING UP FOR THE GOOGLE CLOUD PLATFORM

The first thing we need to do is sign up for Google Cloud.

NOTES:

1. You get a free $300 credit for signing up.

2. There’s no auto-charge when the trial ends.

3. Individual accounts are not available in the European Union.

PREREQUISITES:

1. Have a Google account. Sign up for one if you don’t have one.

PROCEDURE

1. Go to: https://cloud.google.com

2. Click TRY IT FREE.

user_76152_59381320cbaa4.png

3. Log in with your Google account.

4. Select your country and accept the terms:

user_76152_5938139c71af5.png

CONFIGURING THE PROJECT

Now, we can configure our Google Cloud Project.

PROCEDURE

1. Go to the Google Cloud Console in your browser and log in: https://cloud.google.com

2. Click on the active project in the top left section (likely My First Project).

user_76152_5938143444ea7.png

3. Click the + in the popup menu:

user_76152_59381476bf5d6.png

4. Set a project name. Use something like: “your-la-username”. Be sure to substitute your LA username.

5. Take note of the Project ID. GCP will automatically generate one for you. You can change this if you like, but it must be unique to the world of GCP projects.

6. Click Create.

7. There will be a bit of a delay in the creation of the project. After a few moments, you should be able to select it from the Select a Project menu at the top left of the web console view. The Select view will show Recent by default. You may have to click on the All tab to reach your newly created project.

SETTING UP THE GOOGLE CLOUD SDK

PROCEDURE

1. Now, we need to set up the SDK in our local dev environment:

export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
apt-get update && apt-get install google-cloud-sdk -y
apt-get install google-cloud-sdk-app-engine-java -y

2. Next we need to install kubectl in our local dev environment:

sudo sed -i -e 's/true/false/' /usr/lib/google-cloud-sdk/lib/googlecloudsdk/core/config.json
gcloud components install kubectl

Do you want to continue (Y/n)? y

3. If kubectl is not symlinked in /usr/bin, use the folloing command to do so:

cd /usr/bin
ln -s ../lib/google-cloud-sdk/bin/kubectl .

4. Initialize the Google Cloud SDK:

gcloud init

You must log in to continue. Would you like to log in (Y/n)? y

You will need to copy the authorization link into your browser.

Go to the following link in your browser:

Enter the verification code that is generated in the browser.

user_76152_593819db19ea6.png_800.jpg

Enter verification code:

You will be presented with a menu of projects for you to select. Note your menu will look different than mine. Select the project you created previously in Configure The Project.

Pick cloud project to use:
[1] animated-guard-165120
[2] custom-mix-164216
[3] learning-containers
[4] supple-snow-169319
[5] Create a new project
Please enter numeric choice or text value (must exactly match list
item): 4

Configure Google Compute Engine.

Your current project has been set to: [supple-snow-169319].

Do you want to configure Google Compute Engine
(https://cloud.google.com/compute) settings (Y/n)? y

Select the zone to which you want your container clusters to default. Enter the number of the zone you want to use. I will be using us-central1-b.

Which Google Compute Engine zone would you like to use as project
default?
If you do not specify a zone via a command line flag while working
with Compute Engine resources, the default is assumed.
[1] asia-east1-a
[2] asia-east1-c
[3] asia-east1-b
[4] asia-northeast1-b
[5] asia-northeast1-a
[6] asia-northeast1-c
[7] asia-southeast1-b
[8] asia-southeast1-a
[9] europe-west1-b
[10] europe-west1-d
[11] europe-west1-c
[12] us-central1-f
[13] us-central1-b
[14] us-central1-a
[15] us-central1-c
[16] us-east1-b
[17] us-east1-c
[18] us-east1-d
[19] us-east4-b
[20] us-east4-a
[21] us-east4-c
[22] us-west1-b
[23] us-west1-a
[24] us-west1-c
[25] Do not set default zone
Please enter numeric choice or text value (must exactly match list
item): 13

5. You can get a listing of your configuration by running the following command:

gcloud config list

[compute]
region = us-central1
zone = us-central1-b
[core]
account = <ACCOUNT_EMAIL>
disable_usage_reporting = True
project = supple-snow-169319
CREATE THE HELLO-NODE POD AND SERVICE

PROCEDURE

1. Now we can create the container cluster for our project. This will create a container cluster with 3 nodes.

gcloud container clusters create node-cluster

2. Create the hello-node pod that exposes port 8080 by running the following command:

kubectl run hello-node --image=gcr.io/google-samples/node-hello:1.0 --port=8080
deployment "hello-node" created

3. Check the status of your pod. Make sure the status is Running.

kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-node-3056736656-280tt 1/1 Running 0 2m

4. Now you will want to make your pod publicly accessible by creating a load balancer service:

kubectl expose deployment hello-node --type="LoadBalancer"
service "hello-node" exposed

5. Check the status of the service you created:

kubectl get service hello-node
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-node 10.51.249.8 <pending> 8080:31093/TCP 14s

Once the service has an external IP you can access it using your browser. This can take several minutes to complete.

kubectl get service hello-node
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-node 10.51.249.8 130.211.215.233 8080:31093/TCP 2m

1. Using the IP of the service access the site over port 8080 in your browser:

http://<EXTERNAL-IP>:8080
CLEANUP

Now that you are finished, it’s time to delete the service, pod and container cluster.

PROCEDURE

1. You can delete the service by executing the following command:

kubectl delete service hello-node
service "hello-node" deleted

2. Now delete the pod:

kubectl delete deployment hello-node
deployment "hello-node" deleted

3. Lastly, delete the project you created:

gcloud container clusters delete node-cluster
YOU ARE DONE!

You have successfully created a container cluster running a Kubernetes pod and service.

Comments are disabled for this guide.