'How to get pods actually scheduled on master node

I'm trying to gey pods scheduled on the master node. Succesfully untainted the node

kubectl taint node mymasternode node-role.kubernetes.io/master:NoSchedule-

node/mymasternode untainted

But then changing replicas to 4 in the deploy.yaml and apply it all the pods are scheduled on the worker nodes that were workers already.

Is there an extra step needed to get pods scheduled on the master node as well?



Solution 1:[1]

To get pods scheduled on Control plane nodes which have a taint applied (which most Kubernetes distributions will do), you need to add a toleration to your manifests, as described in their documentation, rather than untaint the control plane node. Untainting the control plane node can be dangerous as if you run out of resources on that node, your cluster's operation is likely to suffer.

Something like the following should work

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

If you're looking to get a pod scheduled to every node, usually the approach is to create a daemonset with that toleration applied.

If you need to have a pod scheduled to a control plane node, without using a daemonset, it's possible to combine a toleration with scheduling information to get it assigned to a specific node. The simplest approach to this is to specify the target node name in the manifest.

This isn't a very flexible approach, so for example if you wanted to assign pods to any control plane node, you could apply a label to those nodes and use a node selector combined with the toleration to get the workloads assigned there.

Solution 2:[2]

By default master is tainted for not to schedule any pods on it by adding Tolerations we can allow pods to be schedule on Master but thats not guranteed to make sure its schedule on master only we add nodeSeletor this will ensure pods will only schedule on master.

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  tolerations:
  - key: "node-role.kubernetes.io/master"
    operator: "Exists"
    effect: "NoSchedule"
  nodeSelector:
    node-role.kubernetes.io/master: ""

Proof Of Concept :

Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  8s    default-scheduler  Successfully assigned default/nginx to controlplane
  Normal  Pulled     7s    kubelet            Container image "nginx" already present on machine
  Normal  Created    7s    kubelet            Created container nginx
  Normal  Started    6s    kubelet            Started container nginx

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Mansur Ul Hasan