Google Cloud has a number of compute-related resources including Compute Engine, Kubernetes, and Cloud Run. In this exercise, you install the logging and monitoring agents into a VM running a Nginx server to maximize the metrics to easily view. You also set up a Kubernetes cluster and monitor an application deployed into it.
Objectives
In this lab, you learn how to perform the following tasks:
Set up a VM and a GKE cluster.
Install and use the logging and monitoring agents for Compute Engine.
Add a service to the GKE cluster and examine its logs and metrics.
Setup
Access the lab
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.
After you complete the initial sign-in steps, the project dashboard appears.
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. Set up a VM and a GKE cluster
In this task, you:
Set up a VM running Nginx.
Create a GKE cluster.
Set up a VM to host Nginx
In the Cloud Console, select Navigation menu > Compute Engine > VM instances, then click Create Instance.
Set the following fields:
Name: web-server-vm
Region:
Zone:
Click OS and storage.
If the Image shown is not Debian GNU/Linux 11 (bullseye), click Change and select Debian GNU/Linux 11 (bullseye), and then click Select.
Click Networking.
For Firewall, click Allow HTTP traffic.
Leave the rest of the fields at their default values and click Create.
Create a GKE cluster
To explore a little of what Google Kubernetes Engine offers in the way of logging and monitoring, let's add a cluster, which will come with logging and monitoring enabled by default.
Use the Navigation menu to navigate to the Kubernetes Engine > Clusters page.
Click Create and then click on the Switch to Standard Cluster. Confirm Switch to Standard Cluster.
Set the Name to gke-cluster and Zone to , then under the Cluster settings on the left, select Features.
Verify that Enable Logging is checked and dropbox is set to System and Workloads also verify Enable Cloud Monitoring is checked and System is selected by default in the dropdown, and then press Create.
Once you see the cluster creation start, move on to the next step.
Install Nginx
Switch back to Compute Engine and SSH into the web-server-vm.
Use APT to install Nginx:
sudo apt-get update
sudo apt-get install nginx
Enter Y when prompted.
Verify that Nginx installed and is running:
sudo nginx -v
Switch back to Compute Engine and if you enabled the HTTP access firewall rule, then you should be able to click the external IP. Do so and make sure the Nginx server is up and running.
Copy the URL to the server.
Change to the Cloud Shell terminal window.
Create a URL environmental variable and set it equal to the URL to your server:
URL=URL_to_your_server
Use a bash while loop to place some load on the server. Make sure you are seeing the Welcome to nginx responses:
while true; do curl -s $URL | grep -oP "<title>.*</title>"; \
sleep .1s;done
Task 2. Install and use the logging and monitoring agents for Compute Engine
In this task, you:
Examine the logs and see some data that isn't included.
Install the logging and monitoring agents in the Compute Engine instance.
Re-examine the logs to see the new data.
Examine the logs and see some data that isn't included
A standard Debian Linux image from Google will not have the logging or monitoring agents installed, so you won't have access to metrics from googleapis.com/nginx/ such as:
connections/accepted_count
connections/current
connections/handled_count
request_count
Switch to the Google Console window and navigate to Monitoring > Overview.
Wait for the monitoring workspace to create, and then navigate to Metrics explorer.
Click on Select a metric dropdown and select VM Instance > Instance > CPU utilization.
Click Apply, and set the Filter to instance_name = web-server-vm.
You may not see a spike when you apply the load, since it's not a big load, but you are able to access the metric.
Delete the Filter and the Metric.
Click on Select a metric dropdown and deselect Active.
Select VM Instance > nginx > Requests. Click Apply.
Why is there no data?
Install the logging and monitoring agents in the Compute Engine instance
The data for Nginx requests is missing because without the logging and monitoring agents being installed, the best Google Cloud can do is black-box monitoring. If you want to see more details, then you need to enable white-box monitoring by installing the agents.
Use the Navigation menu to navigate to Compute Engine > VM instances.
Click the SSH link for the web-server-vm.
Check to see if the logging agent is installed/running:
sudo service google-fluentd status
sudo service stackdriver-agent status
Not surprisingly, the services could not be found.
Check to make sure you have the requisite scopes to perform logging and monitoring.
Retest the two agents again and verify they are both active. If you see any "can not take infinite value" warnings, ignore them and if the status is active (running), press CTRL+C and move on to the next step:
sudo service google-fluentd status
sudo service stackdriver-agent status
To fully integrate the server, you enable the status information handler in Nginx by adding a configuration file to the Nginx configuration directory:
Now that the agents are installed and the Nginx plugins have been added, retest the Nginx metric that we examined earlier.
Check the Cloud Shell window and verify that the test loop is still running, and that you are still receiving responses. If not, reset the URL property and restart the while.
Navigate to the Monitoring > Metrics explorer.
Click on Select a metric dropdown and select VM Instance > nginx > Requests, then click Apply.
You may have to wait a few minutes and refresh the page, but you should soon see metric data coming in from Nginx. The monitoring agent is working as it should.
Task 3. Add a service to the GKE cluster and examine its logs and metrics
You created a GKE cluster with logging and monitoring enabled earlier in this exercise. Now, load the HelloLoggingNodeJS application to it, put it behind a load balancer service, and view some metrics for your cluster.
Switch to or reopen the Cloud Shell console.
Break the running test loop with CTRL+C.
Enable the Cloud Build API as it is needed in a few steps:
gcloud services enable cloudbuild.googleapis.com
Clone the https://github.com/haggman/HelloLoggingNodeJS.git repo:
This repository contains a basic Node.js web application that is used for testing.
Change into the HelloLoggingNodeJS folder and open the index.js in the Cloud Shell editor:
cd HelloLoggingNodeJS
edit index.js
Take a few minutes to peruse the code.
In the editor, also take a look at the buildContainer.sh file, package.json file which contains the dependencies, and the Dockerfile which plans the Docker container we generate and deploy to GKE.
Executing the file buildContainer.sh to submit the Dockerfile by Google's Cloud Build to generate a container and store it in your Artifact Registry:
chmod +x buildContainer.sh
./buildContainer.sh
In the k8sapp.yaml file, replace the $PROJECT with your actual project ID. Remember, your project ID is located on the Homepage of your Google Cloud Console and in Qwiklabs just below your temporary Google Cloud password.
Open the k8sapp.yaml file and explore the instructions to Kubernetes to create three hello-logging pods, and then expose them through a LoadBalancer service.
Use the Navigation menu to navigate to Kubernetes Engine, and click on the triple dot icon for your cluster and select Connect.
Copy the command line to configure kubectl.
Switch back to Cloud Shell and execute the command.
Use kubectl to apply your k8sapp.yaml.
kubectl apply -f k8sapp.yaml
Get a list of your services. It may take a minute or two for the new hello-logging-service to appear. Wait for it to get an External IP:
kubectl get services
Once the service appears with the external IP, copy the external IP value.
Open a tab in the browser and paste in the IP. Make sure you see the Hello World message.
Note: If prompted The connection is not secure click Continue to site
Copy the page URL from the browser and switch back to Cloud Shell. Update the URL environmental variable and restart the while loop. Make sure you are seeing the Hello World responses:
URL=url_to_k8s_app
while true; do curl -s $URL -w "\n"; sleep .1s;done
Navigate to the Monitoring > Dashboards and open the GKE dashboard.
Click on Configuration icon next to VIEW ALL and enable Sparklines and click Apply.
On the GKE dashboard, for gke-cluster scroll horizontally and see the charts. If all of the small charts are reading No Data, refresh the page until they start showing readings for CPU and Memory Utilization. You might also want to toggle Off to On to enable auto-refresh of the data.
If you want to examine the different cluster nodes, you can scroll horizontally in Nodes tab and see that the three hello-logging-js-deployments are spread across the nodes. This tab focuses on what's running where, from Cluster, to Node, to Pod.
Switch to the Workloads tab. This is focused on the deployed workloads, grouped by namespace.
Finally, scroll to the Kubernetes Services tab and expand hello-logging-service. This view is more about how services relate to their pods.
In any of the views, if you drill all the way down to one of our hello-logging-js-containers, a right-hand window appears with details. Investigate Incidents, Metrics, and Logs.
Congratulations!
In this exercise, you installed and used logging and monitoring agents on Compute Engine instances, and explored logging and monitoring in a GKE cluster. Nice job.
End your lab
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:
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 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.
Os laboratórios criam um projeto e recursos do Google Cloud por um período fixo
Os laboratórios têm um limite de tempo e não têm o recurso de pausa. Se você encerrar o laboratório, vai precisar recomeçar do início.
No canto superior esquerdo da tela, clique em Começar o laboratório
Usar a navegação anônima
Copie o nome de usuário e a senha fornecidos para o laboratório
Clique em Abrir console no modo anônimo
Fazer login no console
Faça login usando suas credenciais do laboratório. Usar outras credenciais pode causar erros ou gerar cobranças.
Aceite os termos e pule a página de recursos de recuperação
Não clique em Terminar o laboratório a menos que você tenha concluído ou queira recomeçar, porque isso vai apagar seu trabalho e remover o projeto
Este conteúdo não está disponível no momento
Você vai receber uma notificação por e-mail quando ele estiver disponível
Ótimo!
Vamos entrar em contato por e-mail se ele ficar disponível
Um laboratório por vez
Confirme para encerrar todos os laboratórios atuais e iniciar este
Use a navegação anônima para executar o laboratório
Para executar este laboratório, use o modo de navegação anônima ou uma janela anônima do navegador. Isso evita conflitos entre sua conta pessoal e a conta de estudante, o que poderia causar cobranças extras na sua conta pessoal.
In this exercise you will install the logging and monitoring agents into a GCE VM running NGINX, and examine monitoring on GKE
Duração:
Configuração: 0 minutos
·
Tempo de acesso: 120 minutos
·
Tempo para conclusão: 30 minutos