arrow_back

Monitoring GKE with Datadog

Sign in Join
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

Monitoring GKE with Datadog

Lab 1 hour universal_currency_alt 1 Credit show_chart Introductory
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

This lab was developed with our partner, Datadog. Your personal information may be shared with Datadog, the lab sponsor, if you have opted-in to receive product updates, announcements, and offers in your Account Profile.

GSP1167

Google Cloud self-paced labs logo

Overview

Datadog is an observability service for cloud-scale applications, providing monitoring of servers, databases, tools, and services, through a SaaS-based data analytics platform. Google Kubernetes Engine (GKE), a service on the Google Cloud Platform (GCP), is a hosted platform for running and orchestrating containerized applications. Due to Kubernetes’s compartmentalized nature and dynamic scheduling, it can be difficult to diagnose points of failure or track down other issues in your infrastructure. Datadog Agent helps to collect metrics from Docker, Kubernetes, and your containerized applications. In this lab you will run the Datadog Agent in a Kubernetes cluster as a DaemonSet in order to start collecting your cluster and applications metrics, traces, and logs. You can deploy a Datadog Agent with a Helm chart or directly with a DaemonSet object YAML definition.

In this lab, you will be explaining and using those options in a real cluster, checking in real time the features they enable.

Objectives

In this lab, you will learn about using the Helm chart used to install the Datadog Agent. You will learn how to:

  • Deploy a GKE Standard Cluster.
  • Deploy the Datadog agent using Helm.
  • Deploy an application.
  • Check the default dashboard.
  • Check the Logs.
  • Create a custom dashboard.

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.

How to start your lab and sign in to the Google Cloud console

  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. Navigation menu icon

Activate Cloud Shell

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. Cloud Shell provides command-line access to your Google Cloud resources.

  1. Click Activate Cloud Shell Activate Cloud Shell icon at the top of the Google Cloud console.

When you are connected, you are already authenticated, and the project is set to your Project_ID, . The output contains a line that declares the Project_ID for this session:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  1. (Optional) You can list the active account name with this command:
gcloud auth list
  1. Click Authorize.

Output:

ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:
gcloud config list project

Output:

[core] project = {{{project_0.project_id | "PROJECT_ID"}}} Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Task 1. Deploy a GKE Standard Cluster

In Cloud Shell, run the following commands to create a GKE Standard Kubernetes cluster

gcloud container clusters create "datadog" \ --machine-type="e2-medium" \ --num-nodes="2" \ --zone={{{project_0.default_zone|ZONE}}}

Click Check my progress to verify the objective. Deploy a GKE Standard Cluster

After a few minutes this will spin up a new Kubernetes cluster with the name datadog. In the meantime you can move on with the Datadog account creation step.

Task 2. Set up a Datadog trial account and get your Datadog API and App keys

If you already have a trial account set up, you can use that. It is recommended that you do not use your production Datadog account to avoid cluttering the environment with test and training assets.

  1. Navigate to https://us5.datadoghq.com/signup and enter your name, email, company, and a password.

  2. On the next page, you will see a list of available Agent installations. Click Kubernetes.

  3. Click Select API Key, then Create New.

  4. Enter a name and click Save.

  5. Select the row with the new key, and click Use API Key.

  6. Copy the Datadog API key.

copy-api-key.png

  1. In the Cloud Console, navigate to your Cloud Shell window. Type in the following command, replace <YOUR_DATADOG_API_KEY> with the Datadog API key you copied, and then run the command:

    export DD_API_KEY=<YOUR_DATADOG_API_KEY> Note! If you close the Cloud Shell, you'll lose the environment variable you just added. Keep it somewhere safe temporarily, or just leave the page open with the API key as mentioned above in case you need to add it again.
  2. In Datadog, create an App key by navigating to Organization Settings > Application Keys. Click on New Key. Give it some meaningful name. Then copy the key.

  3. Back in the Cloud Console, navigate back to your Cloud Shell window. Type in the following command, replace <YOUR_DATADOG_APP_KEY> with the Datadog Application key you copied, and then run the command:

    export DD_APP_KEY=<YOUR_DATADOG_APP_KEY>
  4. In Datadog's console, enable logging by going to Logs and clicking on Get Started.

  5. Confirm Get Started.

Task 3. Deploy the Datadog Helm chart

In this section, you will deploy the Datadog Helm chart. You can check these default values in the Helm chart Github repository.

  1. Create a values.yaml file by running the following command:
echo "datadog: logs: enabled: true containerCollectAll: true clusterAgent: enabled: true replicas: 2 createPodDisruptionBudget: true agents: tolerations: - key: node-role.kubernetes.io/master effect: NoSchedule clusterChecksRunner: env: - name: DD_KUBELET_TLS_VERIFY value: false" > values.yaml
  1. Start by deploying the chart, passing in your API key:
helm repo add datadog https://helm.datadoghq.com helm repo update helm install datadog -f values.yaml \ --set datadog.apiKey=$DD_API_KEY \ --set datadog.appKey=$DD_APP_KEY \ datadog/datadog Note: you may get a deprecation warning, you can ignore that.

Click Check my progress to verify the objective. Deploy Datadog agent using Helm

  1. Run the following to check the secrets that were created:
kubectl get secrets

You should get an output similar to this:

NAME TYPE DATA AGE datadog Opaque 1 16m datadog-cluster-agent Opaque 1 16m datadog-cluster-agent-token-66x2b kubernetes.io/service-account-token 3 16m datadog-token-tjwfx kubernetes.io/service-account-token 3 16m default-token-kzw56 kubernetes.io/service-account-token 3 28m sh.helm.release.v1.datadog.v1 helm.sh/release.v1 1 16m
  1. The most important one is the one called datadog. This is a secret that was automatically created that contains your API key.

Check that the secret actually contains your API key getting the value and base64 decoding it:

kubectl get secret datadog --template='{{index .data "api-key"}}' | base64 -d
  1. The other two token secrets are the ones used by the service accounts to communicate with the API server. Check the workloads that have been deployed:
kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE datadog-cluster-agent 2/2 2 2 33m
  1. Run the following command to verify the Datadog Agent is running in your environment as a DaemonSet:
kubectl get daemonset

(Output)

NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE datadog 2 2 2 2 2 kubernetes.io/os=linux 33m
  1. Check the status of the Datadog agent:
kubectl exec -ti $(kubectl get pods -l app=datadog -o custom-columns=:metadata.name) -- agent status
  1. Check the output and look at the different checks that are running by default.

Task 4. Deploy an Application

  1. Download the application manifest. This application code lives here
curl https://raw.githubusercontent.com/GoogleCloudPlatform/microservices-demo/main/release/kubernetes-manifests.yaml -o manifest.yaml
  1. Apply the manifest to your cluster
kubectl apply -f manifest.yaml
  1. Watch the status of your deployment
kubectl get po -w

Task 5. Datadog Dashboard

  1. Go to the Datadog dashboard page. Dashboards > Dashboard List.

  2. Click on Kubernetes Cluster Overview Dashboard or alternatively click on this link. You can see high CPU usage.

  3. You can also confirm that some of the pods are stuck in pending.

kubectl get po | grep Pending adservice-694f4ff98-49trp 0/1 Pending 0 4m22s cartservice-859c54495f-d78p8 0/1 Pending 0 4m24s loadgenerator-65779994db-mhb24 0/1 Pending 0 4m23s shippingservice-ff5f4d7d-s974d 0/1 Pending 0 4m23s

The exact pods pending might be differently named, but in any case--you don't have enough CPU or Memory to spin up all the pods.

Task 6. Scale the cluster

  1. GKE has great support for auto scaling node pools based on demand. Set up autoscaling for default-pool.
gcloud container clusters update datadog \ --enable-autoscaling \ --node-pool=default-pool \ --min-nodes=2 \ --max-nodes=5 \ --zone={{{project_0.default_zone|ZONE}}}
  1. After a few minutes you will see this command succeed. And a few minutes later you will see one or two new nodes show up. You can watch the pods using to check that the pods are now all in running state.
kubectl get po -w
  1. Because all your pods had not started before, the application could not run properly. But now that all your pods are running, you can access the application via the public IP address of the LoadBalancer.
kubectl get svc frontend-external -o json | jq '.status.loadBalancer.ingress[].ip'
  1. In your browser, you can visit the ip to see the online boutique website.

Click Check my progress to verify the objective. Scale size of default node pool

Task 7. Check Logs in Datadog

  1. Go to Logs.

  2. Your Apps have been exporting logs that the Datadog agent has been picking up.

  3. You can filter these logs based on service, source, and status. You should see quite a few logs since you have loadgenerator service running.

Congratulations

In this lab, you got hands-on experience using the Datadog Helm Chart and installed the Datadog Agent.

Next Steps / Learn More

Be sure to check out the following labs for more practice with Datadog:

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 April 16, 2024

Lab Last Tested April 16, 2024

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.