简体   繁体   English

如何让 pod 实际调度到 master 节点上

[英]How to get pods actually scheduled on master node

I'm trying to gey pods scheduled on the master node.我正在尝试在主节点上安排 gey pod。 Succesfully untainted the node成功清除节点

kubectl taint node mymasternode node-role.kube.netes.io/master:NoSchedule- kubectl 污点节点 mymasternode node-role.kube.netes.io/master:NoSchedule-

node/mymasternode untainted节点/mymasternode 未受污染

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.但是然后在 deploy.yaml 中将副本更改为 4 并应用它,所有 pod 都安排在已经是工作人员的工作节点上。

Is there an extra step needed to get pods scheduled on the master node as well?是否还需要额外的步骤才能在主节点上安排 pod?

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.要在应用了污点的控制平面节点上安排 pod(大多数 Kubernetes 发行版都会这样做),您需要在清单中添加容忍度,如他们的文档中所述,而不是取消控制平面节点的污点。 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.如果您希望为每个节点安排一个 pod,通常方法是创建一个应用了该容忍度的守护程序集

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.如果您需要将 pod 调度到控制平面节点,而不使用守护程序集,则可以将容忍度与调度信息结合起来,将其分配给特定节点。 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.这不是一种非常灵活的方法,因此例如,如果您想将 pod 分配给任何控制平面节点,您可以将 label 应用于这些节点,并使用节点选择器与容忍度相结合来获得分配在那里的工作负载。

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.默认情况下,master 被污染为不通过添加 Tolerations 在其上安排任何 pod,我们可以允许 pod 在 Master 上安排,但这不能保证确保其仅在 master 上安排我们添加 nodeSeletor 这将确保 pod 仅在 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM