27 Aug 2024 08:15 PM - last edited on 28 Aug 2024 07:22 AM by MaciejNeumann
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:
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")))
Your K8s Entities should now have the corresponding tags automatically applied!