• Home
  • Deploy Dynatrace
  • Set up Dynatrace on container platforms
  • Kubernetes
  • Enable Kubernetes/OpenShift API monitoring
  • Connect your Kubernetes/OpenShift clusters to Dynatrace

Connect your Kubernetes/OpenShift clusters to Dynatrace

Dynatrace version 1.232+

Prerequisites

  1. Set up Dynatrace Operator.

  2. Set the ActiveGate values of the DynaKube configuration file according to the list of parameters.

    Note: To enable ActiveGate, in the ActiveGate section, add routing and/or kubernetes-monitoring to capabilities.

    Example:

    yaml
    activeGate: capabilities: - routing - kubernetes-monitoring ...

Connect your clusters and enable monitoring

You have two options:

  • Connect the containerized ActiveGate to a local Kubernetes API endpoint
  • Connect the containerized ActiveGate to the public Kubernetes API URL

See below for instructions for both options.

Connect to a local Kubernetes API endpoint

ActiveGate version 1.229+

You can enable monitoring by connecting a containerized ActiveGate to a local Kubernetes API endpoint.

There are two ways to connect to the local Kubernetes API endpoint:

  • Let Dynatrace Operator automatically handle the connection. recommended
  • Configure the connection manually

See below for details on both methods.

To connect automatically to the local Kubernetes API endpoint

  1. Apart from the prerequisites needed for setting up monitoring, make sure to also enable the Read entities, Read settings, and Write settings permissions (API v2) for your API token.
  2. Make sure that you have the kubernetes-monitoring capability enabled in your DynaKube custom resource.
  3. Add the following annotation (see example below).
yaml
apiVersion: dynatrace.com/v1beta1 kind: DynaKube metadata: name: dynakube namespace: dynatrace annotations: feature.dynatrace.com/automatic-kubernetes-api-monitoring: "true" spec: ... activeGate: capabilities: - kubernetes-monitoring

Note: After adding this annotation, the name of the cluster displayed in Dynatrace will be the same as the DynaKube custom resource where the annotation is configured. You can change the cluster name displayed in Dynatrace by adding the feature.dynatrace.com/automatic-kubernetes-api-monitoring-cluster-name: "custom-cluster-name" annotation as well. Be sure to replace "custom-cluster-name" with your desired cluster name.

Example:

yaml
apiVersion: dynatrace.com/v1beta1 kind: DynaKube metadata: name: dynakube namespace: dynatrace annotations: feature.dynatrace.com/automatic-kubernetes-api-monitoring: "true" feature.dynatrace.com/automatic-kubernetes-api-monitoring-cluster-name: "custom-cluster-name" spec: ... activeGate: capabilities: - kubernetes-monitoring
  1. Apply your configuration.

Note: To disable the configuration, remove the annotation.

To connect to a local Kubernetes API endpoint manually, you only need to provide the unique Kubernetes cluster ID (the uuid of the kube-system namespace) in Dynatrace web UI. The containerized ActiveGate then identifies the unique cluster ID and sends it over to Dynatrace.

Get the Kubernetes cluster ID

Provide the Kubernetes cluster ID in the Dynatrace web UI

Get the Kubernetes cluster ID

Run the command below and grab the UID from the output.

sh
kubectl get namespace kube-system -o jsonpath='{.metadata.uid}'
sh
oc get namespace kube-system -o jsonpath='{.metadata.uid}'

Provide the Kubernetes cluster ID in the Dynatrace web UI

  1. In the Dynatrace menu, go to Kubernetes.
  2. Select Connect manually.
  3. On the Kubernetes cluster monitoring settings page, provide a Name, and then turn on Connect containerized ActiveGate to local Kubernetes API endpoint.
  4. For Kubernetes cluster ID, enter the UID obtained earlier.
  5. Select Save changes to save your configuration. Note: You can save your configuration even if the ActiveGate isn't ready to connect, and finish the configuration later. To verify if it's ready, select Test configuration.

Change monitoring settings

You can change monitoring settings at any time from your Kubernetes cluster details page.

  1. In the Dynatrace menu, go to Kubernetes.
  2. Find your Kubernetes cluster, and then select Actions > Settings.
  3. Adjust your settings, and then select Save changes.

Delete configuration

To delete the connection to a local Kubernetes API endpoint

  1. In the Dynatrace menu, go to Kubernetes.
  2. Find your Kubernetes cluster, and then select Actions > Settings.
  3. Select Use defaults, and then select Save changes.

Connect to the public Kubernetes API

To connect to the public Kubernetes API, follow the instructions that apply to your Kubernetes version:

  • Kubernetes version 1.24+
  • Kubernetes version earlier than 1.24

Kubernetes version 1.24+

  1. Get the Kubernetes API URL.

    bash
    kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}'
    bash
    oc config view --minify -o jsonpath='{.clusters[0].cluster.server}'

    Note: If you set enableIstio to true in the DynaKube custom resource, use the command below to get the Kubernetes API URL:

    bash
    kubectl -n default get svc/kubernetes -o jsonpath='https://{.spec.clusterIP}'
    bash
    oc -n default get svc/kubernetes -o jsonpath='https://{.spec.clusterIP}'
  2. Create a file named token-secret.yaml with the following content:

yaml
apiVersion: v1 kind: Secret metadata: name: dynatrace-kubernetes-monitoring annotations: kubernetes.io/service-account.name: "dynatrace-kubernetes-monitoring" type: kubernetes.io/service-account-token
  1. Apply the file to create the dynatrace-kubernetes-monitoring secret.
bash
kubectl apply -n dynatrace -f token-secret.yaml
bash
oc apply -n dynatrace -f token-secret.yaml
  1. Get the bearer token.

    bash
    kubectl get secret dynatrace-kubernetes-monitoring -o jsonpath='{.data.token}' -n dynatrace | base64 --decode
    bash
    oc get secret dynatrace-kubernetes-monitoring -o jsonpath='{.data.token}' -n dynatrace | base64 --decode
  2. In the Dynatrace menu, go to Kubernetes and select Connect manually.

  3. On the Kubernetes cluster monitoring settings page, provide a Name, the Kubernetes API URL, and the Bearer token for the Kubernetes cluster.

  4. Select Save changes.

Kubernetes version earlier than 1.24

  1. Get the Kubernetes API URL.

    bash
    kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}'
    bash
    oc config view --minify -o jsonpath='{.clusters[0].cluster.server}'

    Note: If you set enableIstio to true in the DynaKube custom resource, use the command below to get the Kubernetes API URL:

    bash
    kubectl -n default get svc/kubernetes -o jsonpath='https://{.spec.clusterIP}'
    bash
    oc -n default get svc/kubernetes -o jsonpath='https://{.spec.clusterIP}'
  2. Get the bearer token.

    bash
    kubectl get secret $(kubectl get sa dynatrace-kubernetes-monitoring -o jsonpath='{.secrets[0].name}' -n dynatrace) -o jsonpath='{.data.token}' -n dynatrace | base64 --decode
    bash
    oc get secret $(oc get sa dynatrace-kubernetes-monitoring -o jsonpath='{.secrets[0].name}' -n dynatrace) -o jsonpath='{.data.token}' -n dynatrace | base64 --decode
    bash
    oc get secret $(oc get sa dynatrace-kubernetes-monitoring -o jsonpath='{.secrets[1].name}' -n dynatrace) -o jsonpath='{.data.token}' -n dynatrace | base64 --decode
    Special instructions for Rancher distributions to get the API URL and the bearer token

    For Rancher distributions of Kubernetes, you need to use the bearer token and API URL of the Rancher server, because this server manages and secures traffic to the Kubernetes API server. Follow the steps below.

    1. Get the Kubernetes API URL.

      bash
      kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}'
    2. Configure a user.

      In the Rancher web UI, either create a new user or use an existing user to associate with the token. We recommend creating a new user.

    3. Set permissions.

      Make sure the user has either Owner or Custom permissions to the cluster you want to monitor.

      Recommended: select Custom permissions, and be sure to select these two roles: View all Projects and View Nodes.

    4. Create an API key.

      Go to API & Keys and create a key either for your specific account (enter your cluster name) or for all clusters (enter No scope). For security reasons, we recommend selecting the first option.

      Note: Newly created keys display four fields. Make sure to use the content of the field called Bearer token to set up the connection to the Kubernetes API described in the next section.

  3. In the Dynatrace menu, go to Kubernetes and select Connect manually.

  4. On the Kubernetes cluster monitoring settings page, provide a Name, the Kubernetes API URL, and the Bearer token for the Kubernetes cluster.

    Note: For Rancher distributions, you need the bearer token that was created in the Rancher web UI, as described in Special instructions for Rancher distributions to get the API URL and the bearer token above.

  5. Select Save changes.

ActiveGate update behavior

ActiveGate is updated automatically on pod restart whenever there is a new version available, unless the image version is specified in cr.yaml.

Related topics
  • Kubernetes/OpenShift monitoring

    Monitor Kubernetes/OpenShift with Dynatrace.