
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Google Kubernetes Engine provides a managed environment for deploying, managing, and scaling your containerized applications using Google infrastructure. The environment that Kubernetes Engine provides consists of multiple machines (specifically, Google Compute Engine instances) grouped together to form a cluster.
Kubernetes provides the mechanisms through which you interact with your cluster. You use Kubernetes commands and resources to deploy and manage your applications, perform administration tasks and set policies, and monitor the health of your deployed workloads.
In this lab, you deploy the Quiz application into Kubernetes Engine, leveraging Google Cloud Platform resources, including Cloud Build and Artifact Registry, and Kubernetes resources, such as Deployments, Pods, and Services.
In this lab, you learn how to perform the following tasks:
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.
Google Cloud Shell provides command-line access to your Google Cloud resources.
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Example output:
Output:
Example output:
In this section, you clone the git repository containing the Quiz application, configure environment variables, and run the application.
sed
command.GCLOUD_PROJECT
and GCLOUD_BUCKET.
mvn clean install.
Next review and update the Quiz application code in a code editor. You can use the Cloud Shell code editor or the shell editors that are installed on Cloud Shell, such as nano
or vim
. This lab uses the Cloud Shell code editor.
training-data-analyst/courses/developingapps/v1.3/java/kubernetesengine/start
.The folder structure for the Quiz application now reflects how it's deployed in Kubernetes Engine:
frontend
folder: contains the packaged output for the web application.backend
folder: contains the packaged output for the console application.Dockerfile
in the frontend
and backend
folders: configuration files for Docker. Currently empty.*.yaml
: configuration file for the Kubernetes Engine.In Cloud Shell, return to the terminal, then use the following command to copy the output jar
for the frontend application to the frontend
folder:
Configure the Quiz backend application:
Copy the output jar for the backend application to the backend
folder:
In this section you create a Google Kubernetes Engine cluster to host the Quiz application.
In the Console, click Navigation menu > Kubernetes Engine > Clusters.
Then click Create.
Click on SWITCH TO STANDARD CLUSTER and click again to confirm.
To configure the cluster, use the specified values for the properties listed in the following table; leave the properties not listed at the default values:
In Cluster basics:
Property | Value |
---|---|
Name | quiz-cluster |
Zone |
Expand default-pool.
In Security select Allow full access to all Cloud APIs.
Click Create. The cluster will take a couple of minutes to provision.
After the cluster is ready, click on the 3 vertical dots and select Connect.
In Connect to the cluster, copy the first command to the clipboard.
Click OK to close the Connect to the cluster window.
The command is in the form: gcloud container clusters get-credentials quiz-cluster --zone
.
Paste the command into Cloud Shell and press Enter.
Or just click Run in Cloud Shell then Enter.
List the pods in the cluster:
The response should indicate that there are no pods in the cluster.
This response confirms that you have configured security to allow the kubectl
command-line tool to perform operations against the cluster.
In this section, you create a Dockerfile for the application frontend and backend and employ Cloud Build to build images and store them in the Artifact Registry.
In the Cloud Shell code editor, Open Editor, open frontend/Dockerfile
.
Copy and paste the following content into frontend/Dockerfile
:
This script is a series of Dockerfile commands.
The first command, FROM gcr.io/google_appengine/jetty9
, initializes the creation of a custom Docker image using the Google App Engine Jetty 9 image, gcr.io/google_appengine/jetty9
as the starting point.
This second command, VOLUME /tmp
, creates a volume in the container's file system with the path of /tmp
.
The third command, ADD ./quiz-frontend-0.0.1.jar /app.jar
, adds the Jar file, uiz-frontend-0.0.1.jar
for the frontend generated by the Maven packaging process as part of the build process.
This fourth and last command, CMD java -jar /app.jar
, executes when the container runs.
You create the dockerfile for the backend the same way you created the frontend, except the jar
file is added to the backend.
In the Cloud Shell code editor, open backend/Dockerfile
.
Copy and paste the following content into backend/Dockerfile
:
In Cloud Shell, Open Terminal, enter the following command to build the frontend Docker image:
The files are staged into Cloud Storage, and a Docker image will be built and stored in the Artifact Registry. It will take a few seconds.
Build the backend Docker image:
In the console, Click Navigation menu > Artifact Registry. You should see two folders: quiz-frontend and quiz-backend.
Click quiz-frontend. You should see the image name (a hash), tags (latest), and other details.
In this section you will modify template yaml
files that contain the specification for Kubernetes Deployment and Service resources, and then create the resources in the Kubernetes Engine cluster.
In the code editor, open the frontend-deployment.yaml
file. The file skeleton has been created for you. Your job is to replace placeholders with values specific to your project.
Replace the placeholders in the frontend-deployment.yaml
file using the following values:
Placeholder Name | Value |
---|---|
[GCLOUD_PROJECT] | GCP Project ID (Display the Project ID by entering echo $GCLOUD_PROJECT in Cloud Shell) |
[GCLOUD_BUCKET] | Cloud Storage bucket ID for the media bucket in your project. The bucket ID is [GCP_Project_ID]-media . |
[FRONTEND_IMAGE_IDENTIFIER] |
The frontend image identified in the form gcr.io/[GCP_Project_ID]/quiz-frontend
|
Only replace values surrounded with []
.
The result yaml file looks something like this:
The quiz-frontend deployment provisions three replicas of the frontend Docker image in Kubernetes pods, distributed across the three nodes of the Kubernetes Engine cluster.
Save the file.
Open the backend-deployment.yaml
file and replace the placeholders in the backend-deployment.yaml
file using the following values:
Placeholder Name | Value |
---|---|
[GCLOUD_PROJECT] | GCP Project ID (or use echo $GCLOUD_PROJECT ) |
[GCLOUD_BUCKET] | Cloud Storage bucket ID for the media bucket in your project. This will be the same bucket used in frontend-deployment.yaml . (The bucket ID is [GCP_Project_ID]-media .) |
[BACKEND_IMAGE_IDENTIFIER] |
The backend image identified in the form gcr.io/[GCP_Project_ID]/quiz-backend
|
The quiz-backend deployment provisions one replica of the backend Docker image in Kubernetes pods, placed on one of the three nodes of the Kubernetes Engine cluster.
Save the file.
Review the contents of the frontend-service.yaml
file.
In Cloud Shell, provision the quiz frontend deployment:
Provision the quiz backend deployment:
Provision the quiz frontend Service:
Each command provisions resources in Kubernetes Engine. It will take a few minutes to complete the process.
In this section review the deployed Pods and Service and navigate to the Quiz application.
In the console, click Navigation menu > Kubernetes Engine > Workloads. You should see two items: quiz-frontend
and quiz-backend
.
You may see that the pod status is OK or in the process of being created.
Click quiz-frontend to see an overview of quiz-frontend
.
Scroll down to see Managed Pods.
You may see that the quiz-frontend load balancer is being created or is OK. Wait until the Service is OK before continuing. You should see an IP address endpoint when the service is ready.
In Exposing services, under Endpoints, select the IP address and open in the new browser tab.
Take a test to verify the application works as expected.
When you have completed your lab, click End Lab. Google Cloud Skills Boost 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:
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 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.
Questi contenuti non sono al momento disponibili
Ti invieremo una notifica via email quando sarà disponibile
Bene.
Ti contatteremo via email non appena sarà disponibile
One lab at a time
Confirm to end all existing labs and start this one