# How to Re-deploy CoreDNS Pods Only to the Master Nodes.

## Problem

Re-deploy CoreDNS pods only to the master nodes as part of performance improvement. Process to achieve this by editing Clusteraddon and by using taints.

## Environment

* Platform9 Managed Kubernetes - 5.4.0 and Higher.

## Procedure

To implement this via the taint and toleration method, the steps to be performed is to set `watch` flag to `false` in CoreDNS clusteraddon object and manually edit the CoreDNS deployment to add taints.

{% tabs %}
{% tab title="CoreDNS ClusterAddon" %}

```c
Edit watch flag to false in clusteraddon of CoreDNS:

# kubectl edit clusteraddons -n default 91bc678c-7da5-41d0-be51-c295cd0a6453-coredns
```

{% endtab %}
{% endtabs %}

#### **After editing:**

{% tabs %}
{% tab title="CoreDNS ClusterAddon" %}

```c
# kubectl describe clusteraddons -n default 91bc678c-7da5-41d0-be51-c295cd0a6453-coredns
Name:         91bc678c-7da5-41d0-be51-c295cd0a6453-coredns
Namespace:    default
Labels:       sunpike.pf9.io/cluster=91bc678c-7da5-41d0-be51-c295cd0a6453
              type=coredns
Annotations:  <none>
API Version:  sunpike.platform9.com/v1alpha2
Kind:         ClusterAddon

Spec:
  Cluster ID:  91bc678c-7da5-41d0-be51-c295cd0a6453
  Override:
    Params:
      Name:   dnsMemoryLimit
      Value:  170Mi
      Name:   dnsDomain
      Value:  cluster.local
  Type:       coredns
  Version:    1.8.0
  Watch:      false   < ---------------------
```

{% endtab %}
{% endtabs %}

Add toleration to CoreDNS deployment:

{% tabs %}
{% tab title="CoreDNS Deployment" %}

```c
nodeSelector:                                    
      node-role.kubernetes.io/master: ""            <--------- Add 
      priorityClassName: system-cluster-critical
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      serviceAccount: coredns
      serviceAccountName: coredns
      terminationGracePeriodSeconds: 30
      tolerations:
      - key: CriticalAddonsOnly
        operator: Exists
      - effect: NoSchedule                            <--------- Add
        key: node-role.kubernetes.io/master           <--------- Add
        operator: Equal                               <--------- Add 
        value: "true"                                 <--------- Add
```

{% endtab %}
{% endtabs %}

The CoreDNS pods will be re-deploy to master node/s only:

{% tabs %}
{% tab title="CoreDNS Pods" %}

```c
# k get pods -A -owide | grep core
kube-system            coredns-84fffcdbd6-52p4j                     1/1     Running       0          10s   10.20.73.133     10.128.147.114   <none>           <none>
kube-system            coredns-84fffcdbd6-shng9                     1/1     Running       0          10s   10.20.73.134     10.128.147.114   <none>           <none>
kube-system            coredns-88d66bcc7-rlxqr                      1/1     Terminating   0          35m   10.20.165.196    10.128.147.204   <none>           <none>
```

{% endtab %}
{% endtabs %}

## Additional Information

The changes made will not persists across cluster upgrade. The new version CoreDNS yaml post upgrade wipes out the taints and toleration.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://platform9.com/kb/pmk/how-to/how-to-re-deploy-coredns-pods-only-to-the-master-nodes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
