Kubernetes DaemonSet only on master nodes

2/25/2020

Is there a way to run a Kubernetes DaemonSet only on master nodes? I know this is possible with deployments but can this behaviour be replicated with DaemonSets?

-- VBoi
daemon
kubernetes

4 Answers

2/25/2020

Yes, it is called Static pod.

https://kubernetes.io/docs/tasks/configure-pod-container/static-pod/

Put the related kubernetes yaml file to Master's StaticPath (normally it is /etc/kubernetes/manifests)

when the master started, these pods will be run automatically as daemonSet

-- BMW
Source: StackOverflow

2/26/2020

I used a mix of nodeSelector and tolerations to achieve this. Here's the code -

  tolerations:
  - key: node-role.kubernetes.io/master
    operator: Exists
    effect: NoSchedule

  nodeSelector:
    kubernetes.io/role: master
-- VBoi
Source: StackOverflow

2/26/2020

You can add a nodeSelector (similar to deployments) which selects only master nodes in daemonset.

-- anmol agrawal
Source: StackOverflow

2/26/2020

You can use tolerations and node affinity in DaemonSet manifest files.

 Ex:
 ......
 tolerations:
 - key: "node-role.kubernetes.io/master"
   operator: Exists
 affinity:
   nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: "node-role.kubernetes.io/master"
            operator: Exists
   .....
-- Subramanian Manickam
Source: StackOverflow