Loading...
No results found.

Google Cloud Skills Boost

Apply your skills in Google Cloud console

02

Gemini for Cloud Architects

Get access to 700+ labs and courses

Provision Cloud Infrastructure with Gemini

Lab 1 hour 15 minutes universal_currency_alt 5 Credits show_chart Introductory
info This lab may incorporate AI tools to support your learning.
Get access to 700+ labs and courses

Overview

Gemini for Google Cloud is an always-on AI collaborator that provides help to users of all skill levels where they need it. In this lab, you will learn how to use Gemini, an AI-powered collaborator in Google Cloud, to to create, test, and modify a Google Kubernetes Engine (GKE) cluster in Autopilot mode.

Note: Duet AI was renamed to Gemini, our next-generation model. This lab has been updated to reflect this change. Any references to Duet AI in the user interface or documentation should be treated as equivalent to Gemini while following the lab instructions. Note: As an early-stage technology, Gemini can generate output that seems plausible but is factually incorrect. We recommend that you validate all output from Gemini before you use it. For more information, see Gemini for Google Cloud and responsible AI.

Objectives

In this lab, you will learn how to perform the following tasks:

  • Enable Gemini
  • Explore various Google services that you can use to deploy an app to GKE by asking Gemini context-based questions.
  • Prompt Gemini to provide commands that you can use to deploy a basic app to a GKE cluster.
  • Create, explore, and modify the GKE cluster by using Gemini to explain and generate the shell commands.

Setup and requirements

For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:

    • The Open Google Cloud console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab Details panel.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab Details panel.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To view a menu with a list of Google Cloud products and services, click the Navigation menu at the top-left, or type the service or product name in the Search field. Navigation menu icon

Task 1. Enable Gemini

You will first enable Gemini in your Google Cloud project and configure the necessary permissions for your Google Cloud Qwiklabs user account.

  1. Click on the Cloud Shell icon (Cloud Shell icon) in the top-right corner of the Google Cloud console toolbar.

  2. To set your project ID and region environment variables, run the following commands:

PROJECT_ID=$(gcloud config get-value project) REGION={{{project_0.default_region|lab region}}} echo "PROJECT_ID=${PROJECT_ID}" echo "REGION=${REGION}" Note:It is worth noting the region, as it may differ to the sample prompts below.
  1. To store the signed-in Google user account in an environment variable, run the following command:
USER=$(gcloud config get-value account 2> /dev/null) echo "USER=${USER}"
  1. Click Authorize if prompted.

  2. Enable the Cloud AI Companion API for Gemini:

gcloud services enable cloudaicompanion.googleapis.com --project ${PROJECT_ID}
  1. To use Gemini, grant the necessary IAM roles to your Google Cloud Qwiklabs user account:
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member user:${USER} --role=roles/cloudaicompanion.user gcloud projects add-iam-policy-binding ${PROJECT_ID} --member user:${USER} --role=roles/serviceusage.serviceUsageViewer

Adding these roles lets the user use Gemini assistance.

Click Check my progress to verify the objective. Enable the Cloud AI Companion API for Gemini and grant IAM roles

Task 2. Deploy GKE clusters

In this task, you use the Google Cloud console and Cloud Shell to deploy GKE clusters.

For the following example, consider that you are an infrastructure admin who is responsible for setting up infrastructure for a team developing a web application. The organization at large has standardized on containers and Kubernetes, so the team wants to understand how to run their web application on Kubernetes in Google Cloud. The team also wants to understand how to do so with as little infrastructure management overhead as possible.

In this case, you have the existing GKE cluster running a set of microservices that make up an ecommerce web app. With Gemini assistance, you will now identify areas to improve.

  1. Return to your tab with the Google Cloud console.

  2. Refresh the Google Cloud console page.

  3. Click on the Gemini icon (Gemini icon) in the top-right corner of the Google Cloud console toolbar.

  4. Click the Start Chatting button.

  5. Enter the following prompt:

How can I run Kubernetes on Google Cloud without having to own management of nodes and the control plane? Note: When you construct prompts for Gemini, use the same amount of detail and context that you would provide if you were to ask the question of a subject matter expert.

Gemini should respond with something similar to the following:

To run Kubernetes on Google Cloud without having to own management of nodes and the control plane, you can use Google Kubernetes Engine (GKE) in Autopilot mode. In Autopilot mode, Google manages the control plane and system components for you, and also manages your worker nodes. Note: Gemini doesn't use your prompts or its responses as data to train its model. For more information, see How Gemini in Google Cloud uses your data.

From the information that Gemini has provided, it looks like a GKE autopilot cluster will meet our needs.

Task 3: Deploy a GKE Autopilot cluster

In this task, you prompt Gemini on how to deploy a GKE Autopliot cluster.

  1. Enter the following prompt:
How do I create a GKE Autopilot cluster?

Gemini responds with the instructions for creating a cluster using the Google Cloud console and instructions for creating a cluster using the Google Cloud CLI.

Note: When you ask Gemini for help, you should include as much context and specific detail as possible. Because AI-generated responses are based on a vast range of possibilities, it's important for you to be precise.
  1. When you see a response that includes placeholder values such as CLUSTER_NAME, REGION, and PROJECT_ID, adding that information to the prompt could lead to even more useful responses. Refine the prompt again with more detail:
What is the command to create a GKE Autopilot cluster in my current project and in the {{{project_0.default_region|lab region}}} region named gemini-demo using the gcloud CLI?

Gemini should respond with something similar to the following:

gcloud container clusters create-auto gemini-demo --region {{{project_0.default_region|lab region}}} Note: If the command given by Gemini is significantly different from the example above, use the above command instead.
  1. Click on the Cloud Shell icon (Cloud Shell icon) in the Gemini toolbar.

The command is copied to Cloud Shell.

  1. Click Enter to run the command.
Note: You need to wait a few minutes for the cluster deployment to complete.

When provisioning is complete, the Kubernetes Engine > Clusters page looks like this screenshot:

Clusters page

  1. Click the cluster name gemini-demo to view the cluster details.

You can scroll down the page to view more details.

Click Check my progress to verify the objective. Deploy GKE cluster

Task 4 : Deploy a sample web application

Now that you have created a GKE cluster in Autopilot mode, you now decide you would like to test running a sample web application similar to the web application your team will run on this infrastructure. Internally, you see that you have the following container image from Google us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0 bookmarked for testing a containerized web application:

  1. In the Gemini pane, enter the following prompt, and then click Send:
What is the kubectl command to create a deployment called hello-server for the image us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0?

Gemini will respond with something similar to:

To create a deployment called hello-server for the image us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0, you can use the following kubectl command:

kubectl create deployment hello-server --image=us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0

Run the kubectl command in the Cloud Shell.

  1. With the web server now created, you now decide you want to test out provisioning a load balancer in front of the web server to expose it to the internet.

In the Gemini pane, enter the following prompt, and then click Send:

What is the kubectl command to expose this deployment on port 80 and target port 8080 with a load balancer?

Gemini should respond with something similar to the following:

To expose a deployment called hello-server with a load balancer, you can use the following kubectl expose command: kubectl expose deployment hello-server --type LoadBalancer --port 80 --target-port 8080 This will create a Compute Engine load balancer for your container.

While providing more context is always helpful, notice how Gemini was able to pull the deployment name hello-server from the conversation history without it being included in the prompt.

  1. In Cloud Shell, run the command provided by Gemini.

  2. Now you want to see if the web server is running and serving requests properly. To view your deployed application, you need to retrieve the external IP address from the Kubernetes service you created.

Enter the following prompt:

What is the kubectl command to see the external IP address associated with this load balancer?

Gemini should respond with something similar to the following:

To see the external IP associated with a load balancer, you can use the following kubectl command:

kubectl get service hello-server

This will output the name of the service, the type of service, the cluster IP address, the external IP address, and the ports that the service is listening on.
  1. In Cloud Shell, run the command provided by Gemini.

After a few minutes, the above kubectl command will yield the result in an output similar to:

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-server LoadBalancer 34.118.227.57 35.225.15.112 80:31473/TCP 6m18s
  1. Open another tab in your browser and navigate to the external IP address for the cluster.

You should see the hello-app running in the tab.

Clusters page

Click Check my progress to verify the objective. Deploy a sample workload

End your lab

When you have completed your lab, click End Lab. Qwiklabs removes the resources you’ve used and cleans the account for you.

You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.

The number of stars indicates the following:

  • 1 star = Very dissatisfied
  • 2 stars = Dissatisfied
  • 3 stars = Neutral
  • 4 stars = Satisfied
  • 5 stars = Very satisfied

You can close the dialog box if you don't want to provide feedback.

For feedback, suggestions, or corrections, please use the Support tab.

Copyright 2024 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.

Previous Next

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

Use private browsing

  1. Copy the provided Username and Password for the lab
  2. Click Open console in private mode

Sign in to the Console

  1. Sign in using your lab credentials. Using other credentials might cause errors or incur charges.
  2. Accept the terms, and skip the recovery resource page
  3. Don't click End lab unless you've finished the lab or want to restart it, as it will clear your work and remove the project

This content is not currently available

We will notify you via email when it becomes available

Great!

We will contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

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.
Preview