Skip to main content

Creating and Deploying a Google Kubernetes Engine Cluster

Hands-On Lab

 

Photo of Joseph Lowery

Joseph Lowery

Google Cloud Training Architect II in Content

Length

01:00:00

Difficulty

Beginner

Google Kubernetes Engine is very flexible, both in deployment and production — it needs to be in order to satisfy the wide spectrum of use cases and user approaches. In this hands-on lab, we’ll use the Cloud Shell command line from start to finish: first containerizing an app and then deploying and exposing it.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Creating and Deploying a Google Kubernetes Engine Cluster

Introduction

In this hands-on lab, we’ll use the Cloud Shell command line from start to finish: first containerizing an app and then deploying and exposing it.

Solution

On the lab page, right-click Open GCP Console and select the option to open it in a new private browser window (this option will read differently depending on your browser — e.g., in Chrome, it says "Open Link in Incognito Window"). Then, sign in to Google Cloud Platform using the credentials provided on the lab page.

On the Welcome to your new account screen, review the text, and click Accept. In the "Welcome L.A.!" pop-up once you're signed in, check to agree to the terms of service, choose your country of residence, and click Agree and Continue.

Enable the Kubernetes Engine API

  1. From the main Google Cloud console navigation menu, choose APIs & Services > Library.
  2. Search for "Kubernetes", and enable the Kubernetes Engine API.

Clone the Repo to Access the Files

  1. Activate the Cloud Shell by clicking the icon in the top row.

  2. Clone the GitHub repository:

    git clone https://github.com/linuxacademy/content-gc-essentials

  3. Change directory:

    cd content-gc-essentials/gke-lab-01

Create the Docker Image

  1. Still in the Cloud Shell, build the Docker image:

    docker build -t la-container-image .

  2. Configure the Docker command line to authenticate to Container Registry:

    gcloud auth configure-docker

  3. Tag the registry image (you can replace your project ID where indicated by highlighting the code in yellow in the Cloud Shell, which will automatically add it to your clipboard):

    docker tag la-container-image gcr.io/<PROJECT_ID>/la-container-image:v1

  4. Push the image forward (substituting your project ID where indicated):

    docker push gcr.io/<PROJECT_ID>/la-container-image:v1

Create the Kubernetes Engine Cluster

  1. Configure the zone:

    gcloud config set compute/zone us-central1-a

  2. Create the clusters:

    gcloud container clusters create la-gke-1 --num-nodes=4

  3. Get authentication credentials:

    gcloud container clusters get-credentials la-gke-1

  4. Deploy the app (substituting your project ID where indicated):

    kubectl run la-greetings --image=gcr.io/<PROJECT_ID>/la-container-image:v1 --port=80

Expose the Deployed Workload

  1. Expose the deployment:

    kubectl expose deployment la-greetings --type=LoadBalancer --name=la-greetings-service --port=80 --target-port=80

  2. Check its status:

    kubectl get services la-greetings-service

  3. When an external IP address has been generated, copy it and paste it into a new browser tab. It should result in our application.

Conclusion

Congratulations on completing this hands-on lab!