0. 概述

在通常情况下,我们都会让 Kubernetes 帮助我们做决策,将 Pod 调度到对应的 Node 中去运行。但是,有的时候并不能这么随意,我们有着一些要求,于是乎你就需要做一些设定,本文将介绍在 Kubernetes 中,原生支持的所有可能影响调度的字段和设置。

1. 默认调度

节点选择器

通过节点选择器,可以指定 Pod 调度到符合过滤条件的 Node 中,示例:

[[email protected]]# cat node-selector.yaml
... ...
spec:
  nodeSelector:
    kubernetes.io/hostname: 192.168.29.48
  containers:
... ...

2. 高级调度

污点和容忍度

操作

节点亲缘性

操作

      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: gpu
                    operator: In
                    values:
                      - "true"

Pod 亲缘性

操作

 podAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: security
            operator: In
            values:
            - S1
        topologyKey: failure-domain.beta.kubernetes.io/zone

3. 自定义调度器

You can run multiple, custom schedulers alongside the default scheduler and configure which scheduler to use for each pods.

To schedule a given pod using a specific scheduler, specify the name of the scheduler in that pod specification.

... ...
kind: Pod
... ...
spec:
  schedulerName: custom-scheduler 
  containers:
... ...