cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Auto-Tagging specific types of K8s Workloads (DaemonSet, Deployment, StatefulSet, etc...)

bsnurka
Dynatrace Advisor
Dynatrace Advisor

Use Case: We are wanting to automatically tag specific K8s Workload types within Dynatrace with a tag that corresponds to how it is deployed within the K8s Cluster. This can also be extended to apply any other tag you can think of, targeted at specific K8s Workload Types.

Solution: We can create Auto-tagging rules, specifying an entitySelector which will narrow the scope of which K8s entities have tags applied. If we want to target all entities matching a specific Workload type, we can optionally remove the CLOUD_APPLICATION_NAMESPACE and/or KUBERNETES_CLUSTER filters.

 

 

type(CLOUD_APPLICATION),cloudApplicationDeploymentTypes("{WORKLOAD-TYPE}"), toRelationships.isNamespaceOfCa(type("CLOUD_APPLICATION_NAMESPACE"), entityName("{NAMESPACE}"), toRelationships.isClusterOfNamespace(type("KUBERNETES_CLUSTER"), entityName("{K8S-CLUSTER}")))

 

 


We will need to replace the {WORKLOAD-TYPE}{NAMESPACE}, and {K8S-CLUSTER} variables to fit the K8s Workloads in question.

The useable options for {WORKLOAD-TYPE} are:

  • KUBERNETES_CRON_JOB
  • KUBERNETES_REPLICA_SET
  • KUBERNETES_DEPLOYMENT
  • KUBERNETES_DAEMON_SET
  • KUBERNETES_STATEFUL_SET
  • KUBERNETES_REPLICATION_CONTROLLER
  • KUBERNETES_POD

For example, to tag K8s SatefulSet's running in the "dynatrace" namespace on the "orwell" K8s Cluster with "workload-type:stateful-set", we would use the following entitySelector:

 

 

 

type(CLOUD_APPLICATION),cloudApplicationDeploymentTypes("KUBERNETES_STATEFUL_SET"), toRelationships.isNamespaceOfCa(type("CLOUD_APPLICATION_NAMESPACE"), entityName("dynatrace"), toRelationships.isClusterOfNamespace(type("KUBERNETES_CLUSTER"), entityName("orwell")))

 

 

 

  1.  Load the settings for Dynatrace UI
  2. Go to Tags > Automatically applied tags > Click Create Tag Button
  3. For Tag name, enter "workload-type"
  4. Click Add a new rule
    1. Optional tag value = "stateful-set"
    2. Rule Type drop-down select Entity selector
    3. enter the above shared string of text from the code block
  5. Click Preview to view which K8s Entities would match the entitySelector, and have the tag applied.
  6. Repeat step 4 as needed to auto-tag other types of K8s Workloads
  7. Click Save changes

bsnurka_0-1724786970222.png

Your K8s Entities should now have the corresponding tags automatically applied!

bsnurka_0-1724785914092.png

 

0 REPLIES 0

Featured Posts