# Deploy Dynatrace Operator | Host Group by Node pool Name

**URL:** <https://community.dynatrace.com/t/deploy-dynatrace-operator-host-group-by-node-pool-name/47463>\
**Category:** Container platforms\
**Tags:** dynatrace-operator, kubernetes, yaml\
**Created:** [September 3, 2024, 5:34pm UTC](https://community.dynatrace.com/t/deploy-dynatrace-operator-host-group-by-node-pool-name/47463 "2024-09-03T17:34:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RPbiaggio](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@RPbiaggio](https://community.dynatrace.com/u/RPbiaggio)\
**Post date:** [September 3, 2024, 5:34pm UTC](https://community.dynatrace.com/t/deploy-dynatrace-operator-host-group-by-node-pool-name/47463/1 "2024-09-03T17:34:45Z")

</div>

Guys, how are you?

I have a kubernetes cluster with 5 node pools. I would like to define my oneagent host groups according to these node pools, so I would have 5 different host groups in this cluster. Is it possible to do this in yaml? Reference which host group will be applied to which machine pool node?

---

<div class="post-metadata">

**Author:** ![RPbiaggio](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@RPbiaggio](https://community.dynatrace.com/u/RPbiaggio)\
**Post date:** [September 3, 2024, 6:12pm UTC](https://community.dynatrace.com/t/deploy-dynatrace-operator-host-group-by-node-pool-name/47463/2 "2024-09-03T18:12:56Z")

</div>

Maybe if I do this it should work?

```markup
oneAgent:
    cloudNativeFullStack:
      # Configuração para o node pool 1
      - nodeSelector:
          nodepool: "pool1" # Seleciona o node pool "pool1"
        tolerations:
          - effect: NoSchedule
            key: node-role.kubernetes.io/master
            operator: Exists
          - effect: NoSchedule
            key: node-role.kubernetes.io/control-plane
            operator: Exists
          - key: "CriticalAddonsOnly"
            operator: "Equal"
            value: "true"
            effect: "NoSchedule"
        args:
          - --set-host-group=host-group-pool1

      # Configuração para o node pool 2
      - nodeSelector:
          nodepool: "pool2" # Seleciona o node pool "pool2"
        tolerations:
          - effect: NoSchedule
            key: node-role.kubernetes.io/master
            operator: Exists
          - effect: NoSchedule
            key: node-role.kubernetes.io/control-plane
            operator: Exists
          - key: "CriticalAddonsOnly"
            operator: "Equal"
            value: "true"
            effect: "NoSchedule"
        args:
          - --set-host-group=host-group-pool2

      # Configuração para o node pool 3
      - nodeSelector:
          nodepool: "pool3" # Seleciona o node pool "pool3"
        tolerations:
          - effect: NoSchedule
            key: node-role.kubernetes.io/master
            operator: Exists
          - effect: NoSchedule
            key: node-role.kubernetes.io/control-plane
            operator: Exists
          - key: "CriticalAddonsOnly"
            operator: "Equal"
            value: "true"
            effect: "NoSchedule"
        args:
          - --set-host-group=host-group-pool3

```

---

<div class="post-metadata">

**Author:** ![chrismuellner](https://avatars.discourse-cdn.com/v4/letter/c/3ab097/32.png) [@chrismuellner](https://community.dynatrace.com/u/chrismuellner)\
**Post date:** [September 11, 2024, 11:46am UTC](https://community.dynatrace.com/t/deploy-dynatrace-operator-host-group-by-node-pool-name/47463/3 "2024-09-11T11:46:19Z")

</div>

Yes, the expected configuration is a Dynakube per Node pool with a different host group for each.

I’d only change the host group to the dedicated field, as the configuration via _args_ is deprecated. See [Dynakube parameters in the official documentation](https://docs.dynatrace.com/docs/shortlink/dto-params-k8s#spec-oneagent).

---

<div class="post-metadata">

**Author:** ![RPbiaggio](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@RPbiaggio](https://community.dynatrace.com/u/RPbiaggio)\
**Post date:** [September 11, 2024, 1:09pm UTC](https://community.dynatrace.com/t/deploy-dynatrace-operator-host-group-by-node-pool-name/47463/4 "2024-09-11T13:09:51Z")

</div>

Hi&nbsp;[@chrismuellner](https://community.dynatrace.com/user/46582), I made many tests here and this yaml does not work.

I did a lot of testing here and this yaml doesn’t work. Apparently I can’t define multiple nodeselector blocks. The big challenge here is being able to install oneagent on multiple nodes, passing the hostgroup. I wasn’t able to do this, support still hasn’t been able to help me and/or tell me if it’s possible. I’ve already tried putting two dynakube resources in the same file, separate files, installing on nodepool, then another, but nothing works.

Can you help me understand if this is possible?

I don’t know if the need is clear, but my cluster has 10 nodepools, right? I need to install the agent on all nodes, however, segregating the hostgroups according to the nodepools.

Thank you

---

<div class="post-metadata">

**Author:** ![kyle\_harrington](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/kyle_harrington/32/16370_2.png) [@kyle\_harrington](https://community.dynatrace.com/u/kyle_harrington)\
**Post date:** [September 11, 2024, 5:45pm UTC](https://community.dynatrace.com/t/deploy-dynatrace-operator-host-group-by-node-pool-name/47463/5 "2024-09-11T17:45:44Z")

</div>

Howdy!

This is 100% possible, however this does require that multiple dynakubes are used and there are some additional parameters which need to be set to deploy successfully. You will need 1 dynakube CRD for each node pool.

Referentially, i’ve built out the below on a GKE cluster with two node pools: “default-pool” and “super-cool-nodepool”:

```markup
kubectl describe nodes | grep nodepool
                    cloud.google.com/gke-nodepool=super-cool-nodepool
                    cloud.google.com/gke-nodepool=super-cool-nodepool
                    cloud.google.com/gke-nodepool=super-cool-nodepool
                    cloud.google.com/gke-nodepool=default-pool
                    cloud.google.com/gke-nodepool=default-pool
                    cloud.google.com/gke-nodepool=default-pool

```

To get this deployed in Cloud Native Full Stack, I’d recommend the below yaml as a template:

```markup
---
apiVersion: dynatrace.com/v1beta2
kind: DynaKube
metadata:
  name: default-pool
  namespace: dynatrace
spec:
  apiUrl: https://{environmentid}.live.dynatrace.com/api
  tokens: "my-token"
  skipCertCheck: false
  oneAgent:
    hostGroup: default-pool
    cloudNativeFullStack:
      namespaceSelector:
        matchLabels:
          monitor: default 
      nodeSelector:
        cloud.google.com/gke-nodepool: default-pool

```

Some notes on the “whys” here:

1. “name:” needs to be unique to the dynakube CRD as each nodepool requires a different configuration

2. “token:” you can reuse the same token/ secret in the same cluster, but it must be called out via this parameter. if it is not the CRD will look for a token with the same value set in “name:” In my example i am using one token for both CRDS, but you could use a unique token for each CRD/ node pool.

3. “hostGroup:” This is the recommended yaml syntax over “args” as called out by&nbsp;[@chrismuellner](https://community.dynatrace.com/user/46582)

4. “nameSpaceSelector:” Setting some unique form of APM injection in each dynakube CRD is required when leveraging multiple dynakubes in Cloud Native Full Stack or Application Only Mode. These two modes use our CSI drivers by default to perform APM injection, if there are injection rules which&nbsp;&nbsp;overlap or conflict the dynatrace operator will reject the dynakube. please note that my example would look for namespaces with the “default” label, not the “Default” namespace.

```markup
apiVersion: v1
data:
  apiToken: <REDACTED>
  dataIngestToken: <REDACTED>
kind: Secret
metadata:
  name: my-token
  namespace: dynatrace
type: Opaque
---
apiVersion: dynatrace.com/v1beta2
kind: DynaKube
metadata:
  name: default-pool
  namespace: dynatrace
spec:
  apiUrl: https://{environmentid}.live.dynatrace.com/api
  tokens: "my-token"
  skipCertCheck: false
  oneAgent:
    hostGroup: default-pool
    cloudNativeFullStack:
      namespaceSelector:
        matchLabels:
          monitor: default 
      nodeSelector:
        cloud.google.com/gke-nodepool: default-pool
  # Configuration for ActiveGate instances.
  activeGate:
    capabilities:
      - routing
      - kubernetes-monitoring
      - dynatrace-api
    replicas: 1
    resources:
      requests:
        cpu: 500m
        memory: 512Mi
      limits:
        cpu: 1000m
        memory: 1.5Gi
    nodeSelector:
        cloud.google.com/gke-nodepool: default-pool
---
apiVersion: dynatrace.com/v1beta2
kind: DynaKube
metadata:
  name: super-cool-nodepool
  namespace: dynatrace
spec:
  apiUrl: https://{environmentid}.live.dynatrace.com/api
  tokens: "my-token"
  skipCertCheck: false
  oneAgent:
    hostGroup: super-cool-nodepool
    cloudNativeFullStack:
      namespaceSelector:
        matchLabels:
          monitor: super-cool-namespace
      nodeSelector:
        cloud.google.com/gke-nodepool: super-cool-nodepool
  # Configuration for ActiveGate instances.
  activeGate:
    capabilities:
      - routing
      - kubernetes-monitoring
      - dynatrace-api
    replicas: 1
    resources:
      requests:
        cpu: 500m
        memory: 512Mi
      limits:
        cpu: 1000m
        memory: 1.5Gi
    nodeSelector:
        cloud.google.com/gke-nodepool: super-cool-nodepool

```

Which results in the below resources being deployed to the cluster

 ![kyle_harrington_2-1726076685791.png](https://global.discourse-cdn.com/dynatrace/original/2X/8/8f6c793597f04487e53b682c4b42490ceeb0863b.png)

edit: One last note. I removed tolerations as it’s not likely all your node pools are part of the control plane, but they may be relevant to your needs. The tolerations in your previously shared yaml are correct.

---

<div class="post-metadata">

**Author:** ![RPbiaggio](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@RPbiaggio](https://community.dynatrace.com/u/RPbiaggio)\
**Post date:** [September 13, 2024, 12:26pm UTC](https://community.dynatrace.com/t/deploy-dynatrace-operator-host-group-by-node-pool-name/47463/6 "2024-09-13T12:26:19Z")

</div>

[@kyle\_harrington](https://community.dynatrace.com/user/35012),  
Thanks for the answer. This configuration is what I was already doing, with the exception of the namespace selector. I wasn’t using it because I have the same namespace in different nodepools. I will change the strategy. As mentioned, for this type of approach to work, it is mandatory that we use the selector namespace and it is not possible.
