arrow_back

GKE Autopilot: Qwik Start

Join Sign in

GKE Autopilot: Qwik Start

45 minutes 1 Credit

GSP957

Google Cloud self-paced labs logo

Overview

Autopilot is a new managed mode of operation for Google Kubernetes Engine (GKE) in which Google creates, sizes, and automatically scales on your behalf the physical infrastructure needed to run your application workloads.

In this lab, you get hands-on practice containerizing an application and deploying it to an Autopilot cluster using Kubernetes configuration and commands.

Simplifying GKE with Autopilot

On GKE your compute infrastructure consists of individual compute instances, called nodes. The set of nodes dedicated to your application is called a cluster. Powering GKE is Kubernetes, an open source cluster management system that is heavily influenced by over fifteen years of Google's experience running production workloads in containers. Kubernetes draws on the same design principles for running popular Google services at global scale to provide:

  • Automatic management
  • Monitoring and liveness probes for application containers
  • Automatic scaling
  • Rolling updates

With Autopilot, you reap the benefits of Google's ability to optimize and configure a cluster using best practices for high availability and security, monitor the health of the cluster, and recalculate the cluster capacity needed to run your workloads at any given moment.

Autopilot liberates you, the developer, to focus on application development, not operational maintenance. Because you're running on GKE, you're still using Kubernetes to run the mission-critical mix of stateless and stateful services your application requires.

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.

This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

Task 1. Access Cloud Code

A Cloud Code development environment has already been set up to easily deploy workloads to a GKE cluster.

  1. Copy the IDE URL from the Lab details panel.

  2. Paste it into a new browser window:

Note: The lab environment is based on a development environment. In this environment, control the remote GKE Autopilot cluster from the IDE.

Task 2. Clone repo

Retrieve the source code under version control to begin the lab.

  1. In your Cloud Code environment, select the Source Control button from the sidebar.

Source Control button highlighted

  1. Click the Clone Repository button.

  2. Paste the following GitHub repository into the prompted search bar:

https://github.com/subfuzion/voting-demo.git
  1. Click Clone from URL in the dropdown list under the search bar.

  2. Click OK to confirm the location.

Note: If prompted with a pop up asking about trusting the folders, select Yes I trust the Authors.
  1. When prompted to open the folder of the repo, click Open.

Click Check my progress to verify the objective. Clone the Repository

Task 3. Add your cluster to the KubeConfig

A GKE Autopilot cluster has been preprovisioned within the lab. In this section, you will update the Cloud Code's KubeConfig to point to the cluster. Once the update is complete, you can then commence the deployment of the demo application.

  1. Open a new terminal by going to the Navigation Menu and selecting Terminal > New Terminal.

open a new terminal

Existing versions of kubectl and custom Kubernetes clients contain provider-specific code to manage authentication between the client and Google Kubernetes Engine. Starting with v1.26, this code will no longer be included as part of the OSS kubectl. GKE users will need to download and use a separate authentication plugin to generate GKE-specific tokens. This new binary, gke-gcloud-auth-plugin, uses the Kubernetes Client-go Credential Plugin mechanism to extend kubectl’s authentication to support GKE. For more information, you can check out the following documentation.

As part of the setup of the lab, the plugin has already been installed on this instance for you. To have kubectl use the new binary plugin for authentication instead of using the default provider-specific code, use the following steps.

  1. Set export USE_GKE_GCLOUD_AUTH_PLUGIN=True in ~/.bashrc:

echo "export USE_GKE_GCLOUD_AUTH_PLUGIN=True" >> ~/.bashrc
  1. Run the following command:

source ~/.bashrc
  1. Run the following command to force the config for this cluster to be updated to the Client-go Credential Plugin configuration.

gcloud container clusters get-credentials dev-cluster --region us-central1

On success, you should see this message pop up:

Kubeconfig entry generated for dev-cluster.

Click Check my progress to verify the objective. Add cluster to the KubeConfig

Note: It can sometimes take a few minutes for this check to verify.

Task 4. Build and deploy the app

Before we can deploy an application, we need a container for our application. In this environment, you will utilize a skaffold manifest which builds the web and vote containers to google container registry and then deploys your application's Kubernetes manifests which use these container images.

  1. Select the Cloud Code button from the left side panel.

  2. Click the Development Sessions tab from the list of options.

  3. Click the Run on Kubernetes button.

Cloud Code - Kubernetes button

  1. From the dropdown that appears, select v2/skaffold.yaml.

  2. Click Yes to use the current context.

  3. Type qwiklabs and select your default image registry which should be your Project ID.

choose image repository

  1. Watch the progress in the Development Sessions of your Cloud Code - Kubernetes:

Development Sessions

  1. Wait for the build and deployment process to complete.

  • While waiting, click on Status to see the logs of the deployment.

  • You can also click on each individual resource to see isolated logs and output for a particular pod, deployment, or service.

  • Once you see the green check mark for Status SUCCEEDED, you can move on:

Status SUCCEEDED

Note: This same deployment could be done on the command line through Cloud Code's terminal using the skaffold run --default-repo=gcr.io/$PROJECT_ID/voting-app --tail command. Be sure to set your Project ID environment variable by running export PROJECT_ID=$(gcloud config get-value project) before executing the command.

The Stream Application Logs will continue to stream logs from activity in the voting app. This allows for an alternative, more immediate means of monitoring the application within the IDE.

Note: No additional authentication is required and a vastly simplified development workflow is possible.

Click Check my progress to verify the objective. Deploy the App

Task 5. Test the app

Finally, you can test that the application is working as specified.

  1. Select the Cloud Code button from the side panel.

  2. In the Development Sessions tab, scroll down until you locate Deployed Resources.

  3. Click on Deployed Resources to unfold it:

  1. Click on Services.

  2. Click on default/web-external.

  3. Click on External IPs:

External IPs option highlighted

  1. Right click on the value under External IPs and select Copy Resource Name.

  2. Open a new tab in your browser and paste the value as your URL.

  3. You should see the frontend for the voting app:

Voting app displays two options: tabs or spaces

  1. Vote for either TABS or SPACES.

  2. Add /results to the end of the voting app URL to view the voting results so far:

{"results":{"a":1, "b":0}, "success": true}

Click Check my progress to verify the objective. Test the App

Great job! You now have your voting application deployed to a cluster. GKE Autopilot has taken care of the management of the Kubernetes infrastructure.

Task 6. Clean up

  1. Terminate your application by pressing the red square Stop button in your IDE window:

Stop button

  1. Click Yes to confirm that resources should be cleaned up on termination.

This way, Cloud Code automatically cleans up your application resources after termination.

Click Check my progress to verify the objective. Delete App from cluster

Congratulations!

You have just deployed a containerized application to Kubernetes Engine! In this lab you have performed the following tasks:

  • Cloned an external public repository
  • Update the KubeConfig to point to our GKE Autopilot cluster
  • Used Skaffold to create a remote container image without needing to install software
  • Deployed a container to the GKE Autopilot cluster
  • Tested the application using HTTP
  • Cleaned up existing resources

Next steps / Learn more

This lab is part of a series of labs called Qwik Starts. These labs are designed to give you some experience with the many features available with Google Cloud. Search for "Qwik Starts" in the lab catalog to find the next lab you'd like to take!

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated November 18, 2022

Lab Last Tested November 18, 2022

Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.