Te treści nie są jeszcze zoptymalizowane pod kątem urządzeń mobilnych.
Dla maksymalnej wygody odwiedź nas na komputerze, korzystając z linku przesłanego e-mailem.
Overview
In this lab, you deploy the Quiz application into Kubernetes Engine (formerly known as Container Engine), and leverage Google Cloud Platform resources, including Cloud Build and Container Registry, and Kubernetes resources, including Deployments, Pods, and Services.
Objectives
In this lab, you learn how to perform the following tasks:
Create Dockerfiles to package up the Quiz application frontend and backend code for deployment.
Harness Cloud Build to produce Docker images.
Provision a Kubernetes Engine cluster to host the Quiz application.
Employ Kubernetes deployments to provision replicated Pods into Kubernetes Engine.
Leverage a Kubernetes service to provision a load balancer for the quiz frontend.
Setup and requirements
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Google Skills 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.
Activate Google Cloud Shell
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.
You can list the active account name with this command:
[core]
project = qwiklabs-gcp-44776a13dea667a6
Note:
Full documentation of gcloud is available in the
gcloud CLI overview guide
.
Task 1. Preparing the case study application
In this section, you access Cloud Shell, clone the git repository containing the Quiz application, configure environment variables, and run the application.
Clone source code in Cloud Shell
In Cloud Shell, clone the repository for the class:
Configure the case study application and review code
Change the working directory:
cd ~/containerengine/start
To replace the default region in a file with the lab-assigned region, run the following commands:
export APP_REGION={{{project_0.startup_script.app_gcp_region | APP_REGION}}}
export REGION={{{project_0.default_region | REGION}}}
sed -i 's/us-central1/'"$REGION"'/g' prepare_environment.sh
sed -i 's/us-central/'"$APP_REGION"'/g' prepare_environment.sh
Configure the Quiz application:
. prepare_environment.sh
Note: This script file:
Creates a Google App Engine application.
Exports environment variables GCLOUD_PROJECT and GCLOUD_BUCKET.
Runs npm install.
Creates entities in Google Cloud Datastore.
Creates a Google Cloud Pub/Sub topic.
Creates a Cloud Spanner Instance, Database, and Table.
Prints out the Google Cloud Platform Project ID.
In Cloud Shell, click Open Editor.
Navigate to containerengine/start.
Note: The folder structure for the Quiz application changes to reflect how it is deployed in Kubernetes Engine.
The web application is in a folder called frontend.
The worker application code that subscribes to Cloud Pub/Sub and processes messages is in a folder called backend.
There are configuration files for Docker (a Dockerfile in the frontend and backend folder) and Kubernetes Engine (\*.yaml).
Click Check my progress to verify the objective.
Configure the case study application
Task 2. Creating a Kubernetes Engine cluster
In this section, you create a Kubernetes Engine cluster to host the Quiz application.
Create a Kubernetes Engine cluster
In the Cloud Platform Console, on the Navigation menu, click APIs & Services.
Scroll down in the list of enabled APIs and confirm that both of these APIs are enabled:
Kubernetes Engine API
Google Container Registry API
If either API is missing, click + ENABLE APIS AND SERVICES at the top. Search for the above APIs by name and enable each for your current project. (You noted the name of your GCP project above.)
In the Cloud Platform Console, on the Navigation menu, click Kubernetes Engine > Clusters.
Click Create.
Click Configure under Standard: You manage your cluster.
Configure the cluster using the following table:
Property
Value
Name
quiz-cluster
Location type
Zonal
Zone
In the Node pools area, click default-pool
In the Security > Access scopes area, Select Allow full access to all Cloud APIs
Click Create.
Note: The cluster takes a couple of minutes to provision.
Click Check my progress to verify the objective.
Create a Kubernetes Engine Cluster
Connect to the cluster
After the cluster is ready, click the three vertical dots on the right side and then click Connect.
To populate Cloud Shell with the connection command, in Connect to the cluster, click Run in Cloud Shell. The command should resemble this:
kubectl get pods
Note: The response should indicate that there are no pods in the cluster.
This confirms that you have configured security to allow the kubectl command-line tool to perform operations against the cluster.
Task 3. Building Docker images using Cloud Build
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 Container Registry.
Create the Dockerfile for the frontend and backend
In the Cloud Shell code editor, open frontend/Dockerfile.
After the existing text, enter the Dockerfile commands to initialize the creation of a custom Docker image using Google's NodeJS App Engine image as the starting point.
Note: The image you are going to use is: gcr.io/google_appengine/nodejs.
Add the Dockerfile command to copy the contents from the current folder to a destination folder in the image /app/.
Add the Dockerfile command to execute npm install -g npm@8.1.3 as part of the build process to ensure that the container runs a compatible version of npm for the application.
Add the Dockerfile command to execute npm update.
Complete the Dockerfile by entering the statement, npm start, which executes when the container runs:
...frontend/Dockerfile
FROM gcr.io/google_appengine/nodejs
RUN /usr/local/bin/install_node '>=0.12.7'
COPY . /app/
RUN npm install -g npm@8.1.3 --unsafe-perm || \
((if [ -f npm-debug.log ]; then \
cat npm-debug.log; \
fi) && false)
RUN npm update
CMD npm start
Save the Dockerfile.
Repeat the previous steps for the backend/Dockerfile file:
...backend/Dockerfile
FROM gcr.io/google_appengine/nodejs
RUN /usr/local/bin/install_node '>=0.12.7'
COPY . /app/
RUN npm install -g npm@8.1.3 --unsafe-perm || \
((if [ -f npm-debug.log ]; then \
cat npm-debug.log; \
fi) && false)
RUN npm update
CMD npm start
Save the second Dockerfile.
Build Docker images with Cloud Build
In Cloud Shell, build the frontend Docker image:
gcloud builds submit -t gcr.io/$DEVSHELL_PROJECT_ID/quiz-frontend ./frontend/
Note: The files are staged into Cloud Storage, and a Docker image is built and stored in the Container Registry. This takes a few minutes.
In the Cloud Platform Console, on the Navigation menu, click Artifact Registry.
Note: You should see two items: quiz-frontend and quiz-backend.
Click the gcr.io repository.
Click quiz-frontend.
Note: You should see the image name, tags (latest), and size (around 275 MB).
Task 4. Creating Kubernetes Deployment and Service resources
In this section, you modify template yaml files that contain the specification for Kubernetes Deployment and Service resources, and then create the resources in the Kubernetes Engine cluster.
Create a Kubernetes Deployment file
In the Cloud Shell code editor, open the frontend-deployment.yaml file.
Note: 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 name for the media bucket in your project (Display the bucket name by entering echo $GCLOUD_BUCKET in Cloud Shell)
[FRONTEND_IMAGE_IDENTIFIER]
The frontend image identified in the form gcr.io/[Project_ID]/quiz-frontend
Note: The quiz-frontend deployment provisions three replicas of the frontend Docker image in Kubernetes pods, which are distributed across the three nodes of the Kubernetes Engine cluster.
Save the file.
Replace the placeholders in the backend-deployment.yaml file using the following values:
Placeholder Name
Value
[GCLOUD_PROJECT]
GCP Project ID
[GCLOUD_BUCKET]
Cloud Storage bucket ID for the media bucket in your project
[BACKEND_IMAGE_IDENTIFIER]
The backend image identified in the form gcr.io/[Project_ID]/quiz-backend
Note: The quiz-backend deployment provisions two replicas of the backend Docker image in Kubernetes pods, which are distributed across two of the three nodes of the Kubernetes Engine cluster.
Save the file.
Review the contents of the frontend-service.yaml file.
Note: The service exposes the frontend deployment using a load balancer. The load balancer will send requests from clients to all three replicas of the frontend pod.
Execute the Deployment and Service files
In Cloud Shell, provision the quiz frontend Deployment:
kubectl create -f ./frontend-deployment.yaml
Provision the quiz backend Deployment:
kubectl create -f ./backend-deployment.yaml
Provision the quiz frontend Service:
kubectl create -f ./frontend-service.yaml
Note: Each command provisions resources in Kubernetes Engine. This takes a few minutes to complete the process.
Click Check my progress to verify the objective.
Creating Kubernetes Deployment and Service Resources
Task 5. Testing the Quiz application
In this section you review the deployed Pods and Service and navigate to the Quiz application.
Review the deployed resources
In the Cloud Console, on the Navigation menu, click Kubernetes Engine.
Click Kubernetes Engine > Workloads.
Note: 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.
You may need to click refresh a couple times until you see OK.
Click quiz-frontend.
Scroll down to Managed pods.
Note: You should see that there are three quiz-frontend pods.
Note: 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.
Under Endpoints, click the Service IP address.
Note: You should see the Quiz application.
Create a question or take a test.
Note: The application works as expected!
Note: Review
Which Docker command is used to execute a command when the container is being constructed?
FROM
COPY
RUN
CMD
Which Docker command is used to execute a command when the container has been deployed?
FROM
COPY
RUN
CMD
Which Kubernetes command is used to retrieve the list of pods running on a cluster?
kubectl pods list
kubectl deployments list
kubectl get pods
kubectl get deployments
Task 6. Bonus: Deploying the Leaderboard to Kubernetes Engine
When a student completes a quiz, their answers are submitted in an API call back to the server. Your job is to capture the student-submitted answers and the correct answers and save them into Cloud Spanner.
To do this you will:
Create a Cloud Pub/Sub topic called answers.
Create a Cloud Spanner table called Answers with appropriate column names and data types.
Post the answer data to the answers topic.
Create a new answer-backend deployment, where the application subscribes to the answers topic in the console application and inserts the answer data into the Answers table.
Create a handler and pug template in the quiz-frontend to display the data from Cloud Spanner when the user browses to the Leaderboard.
The details are left up to you!
End your lab
When you have completed your lab, click End Lab. Google Skills 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 2026 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.
Moduły tworzą projekt Google Cloud i zasoby na określony czas.
Moduły mają ograniczenie czasowe i nie mają funkcji wstrzymywania. Jeśli zakończysz moduł, musisz go zacząć od początku.
Aby rozpocząć, w lewym górnym rogu ekranu kliknij Rozpocznij moduł.
Użyj przeglądania prywatnego
Skopiuj podaną nazwę użytkownika i hasło do modułu.
Kliknij Otwórz konsolę w trybie prywatnym.
Zaloguj się w konsoli
Zaloguj się z użyciem danych logowania do modułu. Użycie innych danych logowania może spowodować błędy lub naliczanie opłat.
Zaakceptuj warunki i pomiń stronę zasobów przywracania.
Nie klikaj Zakończ moduł, chyba że właśnie został przez Ciebie zakończony lub chcesz go uruchomić ponownie, ponieważ spowoduje to usunięcie wyników i projektu.
Ta treść jest obecnie niedostępna
Kiedy dostępność się zmieni, wyślemy Ci e-maila z powiadomieniem
Świetnie
Kiedy dostępność się zmieni, skontaktujemy się z Tobą e-mailem
Jeden moduł, a potem drugi
Potwierdź, aby zakończyć wszystkie istniejące moduły i rozpocząć ten
Aby uruchomić moduł, użyj przeglądania prywatnego
Najlepszym sposobem na uruchomienie tego laboratorium jest użycie okna incognito lub przeglądania prywatnego. Dzięki temu unikniesz konfliktu między swoim kontem osobistym a kontem do nauki, co mogłoby spowodować naliczanie dodatkowych opłat na koncie osobistym.
In this lab, you deploy the quiz application into Kubernetes Engine, leveraging Google Cloud Platform resources including Container Builder and Container Registry, and Kubernetes resources including Deployments, Pods, and Services.
Czas trwania:
Konfiguracja: 1 min
·
Dostęp na 120 min
·
Ukończono w 120 min