如何将Pod/Deploys强制为主节点? [英] How to force Pods/Deployments to Master nodes?

查看:82
本文介绍了如何将Pod/Deploys强制为主节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了Kubernetes 1.5集群,其中三个主节点被污染了 dedicated = master:NoSchedule .现在我只想在主节点上部署Nginx Ingress Controller,所以我添加了容忍度:

I've setup a Kubernetes 1.5 cluster with the three master nodes tainted dedicated=master:NoSchedule. Now I want to deploy the Nginx Ingress Controller on the Master nodes only so I've added tolerations:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-ingress-controller
  namespace: kube-system
  labels:
    kubernetes.io/cluster-service: "true"
spec:
  replicas: 3
  template:
    metadata:
      labels:
        k8s-app: nginx-ingress-lb
        name: nginx-ingress-lb
      annotations:
        scheduler.alpha.kubernetes.io/tolerations: |
          [
            {
              "key": "dedicated",
              "operator": "Equal",
              "value": "master",
              "effect": "NoSchedule"
            }
          ]
    spec:
    […]

不幸的是,这并没有达到预期的效果:Kubernetes将所有Pod安排在工人身上.当将副本数量扩展到更大数量时,Pod也会部署在工作服务器上.

Unfortunately this does not have the desired effect: Kubernetes schedules all Pods on the workers. When scaling the number of replicas to a larger number the Pods are deployed on the workers, too.

如何仅实现对主节点的调度?

How can I achieve scheduling to the Master nodes only?

感谢您的帮助.

推荐答案

容忍度不是 ,这意味着吊舱必须安排在具有此类异味的节点上.这意味着豆荚可以容忍这样的异味.如果希望将Pod吸引到特定节点,则需要在专用的受主污染节点上附加标签,并在Pod中设置nodeSelector以查找这样的标签.

A toleration does not mean that the pod must be scheduled on a node with such taints. It means that the pod tolerates such a taint. If you want your pod to be "attracted" to specific nodes you will need to attach a label to your dedicated=master tainted nodes and set nodeSelector in the pod to look for such label.

将标签粘贴到您的每个特殊用途节点上:

Attach the label to each of your special use nodes:

kubectl label nodes name_of_your_node dedicated=master

Kubernetes 1.6及更高版本的语法

将nodeSelector添加到您的广告连播中:

Kubernetes 1.6 and above syntax

Add the nodeSelector to your pod:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: nginx-ingress-controller
  namespace: kube-system
  labels:
    kubernetes.io/cluster-service: "true"
spec:
  replicas: 3
  template:
    metadata:
      labels:
        k8s-app: nginx-ingress-lb
        name: nginx-ingress-lb
      annotations:
    spec:
      nodeSelector:
        dedicated: master
      tolerations:
      - key: dedicated
        operator: Equal
        value: master
        effect: NoSchedule
    […]

如果您不喜欢nodeSelector,则可以在spec:下添加affinity::

If you don't fancy nodeSelector you can add affinity: under spec: instead:

affinity:
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
        matchExpressions:
        - key: dedicated
          operator: Equal
          values: ["master"]

1.6版之前的语法

将nodeSelector添加到您的广告连播中:

Pre 1.6 syntax

Add the nodeSelector to your pod:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-ingress-controller
  namespace: kube-system
  labels:
    kubernetes.io/cluster-service: "true"
spec:
  replicas: 3
  template:
    metadata:
      labels:
        k8s-app: nginx-ingress-lb
        name: nginx-ingress-lb
      annotations:
        scheduler.alpha.kubernetes.io/tolerations: |
          [
            {
              "key": "dedicated",
              "operator": "Equal",
              "value": "master",
              "effect": "NoSchedule"
            }
          ]
    spec:
      nodeSelector:
        dedicated: master
    […]

如果您不喜欢nodeSelector,还可以添加如下注释:

If you don't fancy nodeSelector you can also add an annotation like this:

scheduler.alpha.kubernetes.io/affinity: >
  {
    "nodeAffinity": {
      "requiredDuringSchedulingIgnoredDuringExecution": {
        "nodeSelectorTerms": [
          {
            "matchExpressions": [
              {
                "key": "dedicated",
                "operator": "Equal",
                "values": ["master"]
              }
            ]
          }
        ]
      }
    }
  }

请记住,NoSchedule不会驱逐已安排的Pod.

Keep in mind that NoSchedule will not evict pods that are already scheduled.

以上信息来自 https://kubernetes.io/docs/user-指南/节点选择/,那里有更多详细信息.

The information above is from https://kubernetes.io/docs/user-guide/node-selection/ and there are more details there.

这篇关于如何将Pod/Deploys强制为主节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆