Skip to main content

Deploying to a Google Kubernetes Engine Cluster

Hands-On Lab

 

Photo of Joseph Lowery

Joseph Lowery

Google Cloud Training Architect II in Content

Length

00:30:00

Difficulty

Beginner

The strength and flexibility of Kubernetes is built around the concept of containerized applications, which are deployed differently from non-containerized apps. In this hands-on lab, you’ll complete all the steps from creating a Kubernetes cluster to confirming the deployed application, including creating the Docker image of your application, pushing that image to Container Registry, deploying the workload, and then configuring a load balancer to expose 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.

Deploying to a Google Kubernetes Engine Cluster

In this hands-on lab, we’ll complete all the steps from creating a Kubernetes cluster to confirming the deployed application, including creating the Docker image of our application, pushing that image to Container Registry, deploying the workload, and then configuring a load balancer to expose it.

How to Log in to Google Lab Accounts

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.

You're now logged in to the Google Cloud Platform console.

Deploying to Google Kubernetes Engine

Now, on to the lab!

Create the Kubernetes Engine cluster.

  1. Navigate to Kubernetes Engine > Clusters.
  2. Click Create cluster.
  3. Under Cluster templates, leave it set as Standard cluster.
  4. Under 'Standard cluster' template:
    • Name the cluster (e.g., "la-standard-cluster-1").
    • Change the number of nodes to 4.
    • Leave all other settings at their default.
  5. Click Create.

Get the files.

  1. Click the Activate Cloud Shell icon in the top navigation bar.

  2. In Cloud Shell, clone the GitHub repository:

    git clone https://github.com/linuxacademy/content-gcpro-developer
  3. Change directory:

    cd content-gcpro-developer/kubernetes-engine-lab

Configure the config.yaml file.

  1. Click the pencil icon at the top of Cloud Shell to launch Cloud Shell Editor.
  2. At the top, click to expand the content-gcpro-developer folder, then the kubernetes-engine-lab folder, and then click the config.yaml file.
  3. On line 32, replace [PROJECT_ID] with your project ID, which you'll see in the Cloud Shell.
  4. In the File menu, select Save.

Build the containerized Docker image.

  1. In the Cloud Shell, execute the following command:

    docker build -t la-container-image .

Push the containerized app into the Container Registry.

  1. In the Cloud Shell, configure Docker to use the gcloud command:

    gcloud auth configure-docker

    When the warning pops up, enter Y.

  2. Tag the image with the registry name (replacing <PROJECT_ID> with your project ID):

    docker tag la-container-image gcr.io/<PROJECT_ID>/la-container-image:v1
  3. Push the image to the Container Registry:

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

Confirm the operation.

  1. Head back to the GCP console.
  2. Navigate to Container Registry > Images.
  3. Confirm the existence of la-container-image.

Deploy the workload.

  1. Navigate to Kubernetes Engine > Workloads.
  2. Expose the info panel.
  3. Make sure Existing container image is selected.
  4. For Image path, click Select.
  5. In the pop-up, expand la-container-image, select the listed container image, and click Continue.
  6. Click Continue.
  7. On the next page, leave the values at their default.
  8. Click Deploy.

Increase the number of pods.

  1. Navigate to the YAML tab.
  2. From the navigation at the top, select Edit.
  3. On line 17, change the number of replicas to 4.
  4. Click Save.
  5. Confirm the operation.

Expose the deployment.

  1. On the Deployment details page, click Expose.
  2. Set the Service type to Load balancer.
  3. Click Expose.
  4. Confirm by clicking the External endpoints IP address.

Conclusion

Congratulations on completing this lab!