Tag Kubernetes Clusters, Workloads, and Pods in Dynatrace for Better Monitoring

please let me know if they are working ok of is something missing. :+1:

Hello @DanielS

First of all, thank you for all your support.Do we need to configure the following rules to make a management zone for a particular namespace?

  • type(KUBERNETES_CLUSTER),entityName.in(“<YOUR KUBERNETES CLUSTER NAME>”) type(CLOUD_APPLICATION_NAMESPACE),toRelationships.isClusterOfNamespace(type(KUBERNETES_CLUSTER),entityName.in(“<YOUR KUBERNETES CLUSTER NAME>”))
  • Dimensional rule for METRIC where DIMESION k8s.cluster.name equals YOUR CLUSTER NAME

The following rules have an issue with the relationship.

  • type(CONTAINER_GROUP_INSTANCE),toRelationships.isCgiOfNamespace(type(CLOUD_APPLICATION_NAMESPACE),entityName.in(“XYZ”))
    entitySelector The entitySelector has an invalid relationship defined: CLOUD_APPLICATION_NAMESPACE IS_CGI_OF_NAMESPACE CONTAINER_GROUP_INSTANCE
  • type(PROCESS_GROUP_INSTANCE),fromRelationships.isMainPgiOfCgi(type(CONTAINER_GROUP_INSTANCE),toRelationships.isCgiOfNamespace(type(CLOUD_APPLICATION_NAMESPACE),entityName.in(“XYZ”)))
    entitySelector The entitySelector has an invalid relationship defined: CLOUD_APPLICATION_NAMESPACE IS_CGI_OF_NAMESPACE CONTAINER_GROUP_INSTANCE

Also, the user has a 403 permission issue while accessing the CPU-limit quota saturation of the namespace. Will the above/or missing rules cover this as well?

Regards,

Babar

Hi @Babar_Qayyum let me replicate the rules in my environment and I reach you.

Now, for the user to enter to the section of Anomaly detection of the namespace, it must have the following policy:

ALLOW settings:objects:read, settings:objects:write, settings:schemas:read
WHERE settings:schemaId = "builtin:anomaly-detection.kubernetes.namespace";

Look here @Babar_Qayyum, if you try to access it through the Kubernetes menu, you won’t see anything, but in Kubernetes Workloads menu you will only see the namespace with the entity ID that you use in the rules.

Sorry I didn’t have time to test it yesterday, but today I tested everything in my environment. Do not hesitate to contact me. Please let me know if the rules worked for you. I edited my previous answer to prevent incorrect rules from confusing anyone.

Hello @DanielS

Once again, thank  you for all your great support. Mostly, things worked as expected. I faced a challenge with the following rule while applying the automatic tagging.

type(CLOUD_APPLICATION_INSTANCE),toRelationships.isNamespaceOfCai(type(CLOUD_APPLICATION_NAMESPACE),entityId(“CLOUD_APPLICATION_NAMESPACE-XXXXXXXXXXXXX”))
entitySelector Entity selector contains type which does not support automatically applied tags

What about the Dimensional rule for METRIC? Do we need to include it in the management zone? What should be the dimension keys in case they are required?

Regards,

Babar

Hello @DanielS

Will the policy apply on the environmental/or management zones level? How can it be assigned only to an individual management zone?

Regards,

Babar

Hello, your welcome @Babar_Qayyum  you are not doing anything wrong and is not an error, as you can see in this post  auto-tags for type CLOUD_APPLICATION_INSTANCE is not supported due to performance implications.

From the test in my environment I didn’t require the DIMENSIONAL Metric, but that depends on what kind of permissions you want to give to the user.

You apply the policy under the environment but you give the group a Permission under the MZ only.

Hello @DanielS

Thank you for sharing the post. In the post, it is mentioned that we can apply the manual tag on the Pods level, whereas, I do not see this option in the settings except for the Container.

Regards,

Babar

Hello @DanielS

What is the entity selector rule to associate the Kubernetes node with a specific Namespace/Pods?

Regards,

Babar

Hey guys.

All good?

Unfortunately, it is only possible to add tags to pods manually through the Dynatrace API.

Something that should be simple, but unfortunately it isn’t (it could be easier).

I managed it as follows:

curl -L -X POST ‘https://{environmentid}.live.dynatrace.com/api/v2/tags?entitySelector=type%28CLOUD_APPLICATION_INSTANCE%29%2CtoRelationships.isClusterOfCai%28type%28KUBERNETES_CLUSTER%29%2CentityName.in%28%22{YOUR_CLUSTER_NAME_HERE}%22%29%29’ \
-H ‘Authorization: Api-Token {YOUR_API_TOKEN_HERE}’ \
-H ‘Content-Type: application/json’ \
--data-raw '{
“tags”: [
{
“key”: “{YOUR_TAG_HERE}”
}
]
}’

Entities.write token required, this cURL is based on the CMD.

Now I need to try to create a management zone based on these manual tags.

Hi,
I want to add tags to workload, How can I doo that .I want to have tags lik app name , k8s cluster name  to each workload. Can someone  tell , if this is possible and how  to do that.

Regards,
Heramb Sawant

Yes, you can do that. To better understand your request, you want to include tags with the name of your application and the name of the cluster in workloads, right? If so, you can do this in several ways. For example:

Using the following expression:

type(CLOUD_APPLICATION),entityId(“CLOUD_APPLICATION-{YOUR WORKLOAD ID}”)

This expression will automatically set a tag for all workloads (Cloud Application) with the IDs specified within the braces after entityId.

Here is a visual example I used in my case:

This documentation shows the types of selectors you can use in an expression.

Hi guys,

Thank you for this thread.

Quick question here, we run a managed environment, and I am trying to tag all services, processes, workloads, pods running on an AWS EKS cluster based on cluster name e.g. or I have already created the management zone for it and I’d use that.

Is it possible to do it via auto tags?

It does not allow me to use types in the entity selector, and I am not able to use the names of the workloads as the k8s clusters I am trying to tag are running many different applications in hundreds of pods/workloads, and I am trying to add a general tag to all running on the selected cluster.

Is it possible some way?

Thanks!

Hi@Gabor I wrote a lot of posts here helping to make auto tags, there is a series of them using the Kubernetes Cluster name. I think that might help you to achieve what you want.

@DanielS Thanks!

Can I apply this to Kubernetes workloads based on their type? For example, can it return only those with the type Deployments or Pods?

Yes @HuseynNajafli , you could use:

type(CLOUD_APPLICATION),cloudApplicationDeploymentTypes("KUBERNETES_STATEFUL_SET")
type(CLOUD_APPLICATION),cloudApplicationDeploymentTypes("KUBERNETES_DEPLOYMENT")
type(CLOUD_APPLICATION),cloudApplicationDeploymentTypes("KUBERNETES_POD")

Hope it helps!!!