• 通过标签绑定 
spec:
  nodeSelector:
    bigdata-node: bigdata
  containers:
    - env:

pod只能运行在有bigdata-node: bigdata 标签的node节点

  • 通过node name绑定
spec:
  nodeName: test-oc08
  containers:
    - env:

pod只能运行在名为test-oc08节点上

 

  • node的亲和力
apiVersion: v1
kind: Pod
metadata:
  name: with-node-affinity
spec:
  affinity:
    nodeAffinity:  #节点选择
      requiredDuringSchedulingIgnoredDuringExecution: #定义必要规则
        nodeSelectorTerms:
        - matchExpressions:
          - key: e2e-az-NorthSouth  #必须匹配的键/值对(标签)
            operator: In 
            values:
            - e2e-az-North #必须匹配的键/值对(标签
            - e2e-az-South 
  containers:
  - name: with-node-affinity
    image: docker.io/ocpqe/hello-pod

该规则要求将pod放置在节点上,且节点的标签的关键字是e2e-az-NorthSouth,其值是e2e-az-North或者e2e-az-South

apiVersion: v1
kind: Pod
metadata:
  name: with-node-affinity
spec:
  affinity:
    nodeAffinity: 
      preferredDuringSchedulingIgnoredDuringExecution: #定义首选规则
      - weight: 1  #权重
        preference:
          matchExpressions:
          - key: e2e-az-EastWest 
            operator: In 
            values:
            - e2e-az-East 
            - e2e-az-West 
  containers:
  - name: with-node-affinity
    image: docker.io/ocpqe/hello-pod

该节点具有标签的关键字为e2e-az-EastWest且其值为e2e-az-East或者e2e-az-West是该Pod的首选项的节点

  •  pod间亲和性和反亲和性
apiVersion: v1
kind: Pod
metadata:
  name: with-pod-affinity
spec:
  affinity:
    podAffinity: #亲和性
      requiredDuringSchedulingIgnoredDuringExecution: 
      - labelSelector:
          matchExpressions:
          - key: security 
            operator: In 
            values:
            - S1 
        topologyKey: failure-domain.beta.kubernetes.io/zone
  containers:
  - name: with-pod-affinity
    image: docker.io/ocpqe/hello-pod

pod必须部署在一个节点上,这个节点上至少有一个正在运行的pod,这个pod中security=S1

apiVersion: v1
kind: Pod
metadata:
  name: with-pod-antiaffinity
spec:
  affinity:
    podAntiAffinity: #反亲和性
      preferredDuringSchedulingIgnoredDuringExecution: 
      - weight: 100 
        podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: security 
              operator: In 
              values:
              - S2 
          topologyKey: kubernetes.io/hostname
  containers:
  - name: with-pod-affinity
    image: docker.io/ocpqe/hello-pod

pod不太会部署在一个节点上,这个节点上正在运行的pod中有security=S2

  • node的污点和

NoSchedule  #新pod不会被调到该节点,已经存在的pod不会影响

PreferNoSchedule #新pod尽量避免不会调度到该节点,已经存在的pod不会影响

NoExecute  #新pod不会被调到该节点,已经存在的pod将会被删除

spec:
  taints:
  - effect: NoSchedule
    key: key1
    timeAdded: null
    value: value1

给节点添加污点

spec:
  tolerations:
  - key: "key1"
    operator: "Equal"
    value: "value1"
    effect: "NoSchedule"

pod容忍污点

转载于:https://www.cnblogs.com/37yan/p/8673292.html

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐