Difficulty: Beginner
Estimated Time: 10 minutes

In this section, you are going to install the Datadog Agent in your environment. To do this we apply a DaemonSet that defines that one Agent should run per host. The first step is to set up the various role-based access control permissions needed for the Agent. You will create a ClusterRole, a ServiceAccount, and a ClusterRoleBinding (you will see the actual commands on the next page).

Next, create and apply a manifest for the Agent. In the hands-on exercise, you will see some of the interesting aspects of the manifest.

Once the Agent is deployed, running kubectl get daemonset will return information about how many agents are running.

Let’s move on to see this in action.

Introduction to Kubernetes Monitoring

Step 1 of 3

Installing the Agent

  1. To get started we need to set a few permissions. The first one is to create a role scoped to the cluster. This role will get and update the ConfigMaps, list and watch the Events, get, update, and create Endpoints, and list the componentstatuses resource. Run the following command on the master: kubectl create -f "https://raw.githubusercontent.com/DataDog/datadog-agent/master/Dockerfiles/manifests/rbac/clusterrole.yaml" You can discover what this role is giving access by opening the url above in your browser. But defining the role alone doesn’t really do anything yet
  2. Next create the service account: kubectl create -f "https://raw.githubusercontent.com/DataDog/datadog-agent/master/Dockerfiles/manifests/rbac/serviceaccount.yaml"
  3. The previous two steps are then linked together in the clusterrolebinding which binds the service account to the clusterrole: kubectl create -f "https://raw.githubusercontent.com/DataDog/datadog-agent/master/Dockerfiles/manifests/rbac/clusterrolebinding.yaml"
  4. The next step is to create the manifest for the Datadog agent and apply it to the cluster. You can find the manifest in the documentation (link to docs), but one is already in the k8s-yaml-files directory. Click on the file to see what’s in there If you compare it with the documentation you may notice that the first block that defines the api-key as a secret is not included. This step has already been completed as part of the provisioning of the training environment.
  5. Apply this manifest using the following command: kubectl apply -f k8s-yaml-files/datadog-agent.yaml
  6. Everything should be running now. To verify, run: kubectl get daemonset You should see a list of how many agents are installed and running.
  7. But wait, we have a cluster that is running on two servers, why aren’t there two agents running. Normally, only the nodes in the cluster will run the agent, but it’s also possible to run the agent on master if you add the tolerance to the pod. After line 16 in datadog-agent.yaml, add the following:

    tolerations:
    - key: node-role.kubernetes.io/master
      effect: NoSchedule
    

    tolerations: should be at the same indent level as containers: below it

  8. Now apply the file again: kubectl apply -f k8s-yaml-files/datadog-agent.yaml

  9. Get the daemonset again and you should see two agents are running.
  10. Open the datadog-agent.yaml file. Notice that many of the configuration options for the agent are defined with environment variables.