节点亲和

节点亲和

   运维菜鸟     2022年3月20日 17:56     1757    

节点亲和有两种方法

1、必须满足规则才能将pod调度到node(硬限制)

参数:requiredDuringSchedulingIgnoredDuringExecution

 

2、配置文件中优先满足指定规则,但不强求(软限制)

参数:preferredDuringSchedulingIgnoredDuringExecution

 

模版写法

affinity:

  nodeAffinity:

这里配置任意一个规则

preferredDuringSchedulingIgnoredDuringExecution

    requiredDuringSchedulingIgnoredDuringExecution:

      nodeSelectorTerms:

      - matchExpressions:

        - key: kubernetes.io/hostname   #标签

          operator: NotIn             #条件

          values:

          - k8s-node3                #

条件:

In:label 的值在某个列表中
NotIn:label 的值不在某个列表中
Gt:label 的值大于某个值
Lt:label 的值小于某个值
Exists:某个 label 存在
DoesNotExist:某个 label 不存在 


下边是示例

apiVersion: apps/v1

kind: Deployment

metadata:

  name: node-affinity

  labels:

    app: node-affinity

spec:

  replicas: 2

  selector:

    matchLabels:

      app: node-affinity

  template:

    metadata:

      labels:

        app: node-affinity

    spec:

      containers:

      - name: nginx

        image: nginx

        ports:

        - containerPort: 80

          name: nginxweb

      affinity:

        nodeAffinity:

          requiredDuringSchedulingIgnoredDuringExecution:

            nodeSelectorTerms:

            - matchExpressions:

              - key: kubernetes.io/hostname

                operator: NotIn

                values:

                - k8s-node1

          preferredDuringSchedulingIgnoredDuringExecution:

          - weight: 1

            preference:

              matchExpressions:

              - key: nginx

                operator: In

                values:

                - right


文章评论

0

其他文章