Difficulty: Beginner
Estimated Time: 10 minutes

In this hands-on section we want to start working with logs on Kubernetes. As we discussed on the previous page, logs are a key source of information for Kubernetes and you will need to use the logs to get access to all the relevant information about how your kubernetes environment as well as the applications running on top are performing. Our goal in this hands-on section is to enable the collection of logs with Datadog and to get a basic introduction to their use in the product. You can go into further detail about logs in the dedicated course on this platform.

Working with Logs in Kubernetes

  1. Once your environment is up and running, log into the Datadog application. Verify that metrics from the environment are coming in to the platform.

  2. Navigate to Logs in the Datadog application. If the feature hasn't been enabled, click the Get Started button and then the Start Trial button.

  3. On the next page you will see the instructions for getting your logs into Datadog. We already have a Datadog yaml file, but we need to add the information listed in the second and third textboxes.

  4. Run the agent status command to see that logs are not being collected yet. kubectl exec $(kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep datadog) -- agent status

    If you get error: unable to upgrade connection: container not found ("datadog-agent"), the datadog agent hasn't had time to launch completely.

  5. Open the datadog-agent.yaml file in the editor to the right. Scroll down to the envsection. Add the following:

    - name: DD_LOGS_ENABLED
      value: "true"
    - name: DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL
      value: "true"
    

    You need to make sure the indent level is correct. All of the - name: keys under env: should be at the same level.

  6. Scroll down to volumeMounts: and add the following:

    - name: pointerdir
      mountPath: /opt/datadog-agent/run
  7. Finally go down to volumes: and add the following:

    - hostPath:
        path: /opt/datadog-agent/run
      name: pointerdir
  8. Apply your new datadog-agent yaml file: kubectl apply -f k8s-yaml-files/datadog-agent.yaml

    Note that this is applying without first deleting due to the updateStrategy being set to RollingUpdate. Also, if there are any errors with indentation, the command will give you feedback about what needs to be fixed.

  9. You can then verify that the logs are being collected by running the agent status command again: kubectl exec $(kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep datadog) -- agent status

  10. Return to Logs in the Datadog application and you should see logs starting to appear.

We will look at enabling logs for specific integrations in a later section.