k8s污点与容忍

参数概念

  • NoSchedule 新的不能容忍的pod不能再调度过来,但是之前运行在node节点中的Pod不受影响
  • NoExecute 新的不能容忍的pod不能调度过来,老的pod也会被驱逐
  • PreferNoScheduler 表示尽量不调度到污点节点中去

标记污点命令

# 添加taint污点命令
kubectl taint nodes k8s-master key=value:NoSchedule
kubectl taint nodes k8s-master key=value:NoExecute
kubectl taint nodes k8s-master key=value:PreferNoSchedule

# 查看taint污点命令
kubectl describe node k8s-master|grep Taints

#删除污点命令
kubectl taint node k8s-01 key:NoSchedule-

配置容忍参数

  tolerations:      #添加容忍策略
    - key: "key"    #对应我们添加节点的变量名
      operator: "Equal"    #操作符
      value: "value"    #容忍的值   key=value对应
      effect: NoExecute   #添加容忍的规则,这里必须和我们标记的污点规则相同

实际案例

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-muban
  namespace: mysql
  labels:
    app: mysql-muban
spec:
  replicas: 1
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: mysql-muban
  template:
    metadata:
      labels:
        app: mysql-muban
    spec:
      containers:
      - name: mysql-muban
        image: mysql:v5.7.22
        volumeMounts:
        - mountPath: /var/lib/mysql
          name: mysqldb-muban
        - mountPath: /etc/mysql
          name: mysqlconf-muban
        env:
        - name: TZ
          value: Asia/Shanghai
        - name: MYSQL_ROOT_PASSWORD
          value: Root123+
        ports:
        - containerPort: 3306
          name: mysql-muban
        resources:
          requests:
            cpu: 1
            memory: 1G
          limits:
            cpu: 4
            memory: 4G
      volumes:
      - name: mysqldb-muban
        hostPath:
          path: /data/mysql/muban/mysqldb
          type: Directory
      - name: mysqlconf-muban
        hostPath:
          path: /data/mysql/muban/conf
          type: Directory
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: effect
                operator: In
                values:
                - mysql
      tolerations:     
        - key: "key"  
          operator: "Equal"  
          value: "value"  
          effect: NoExecute
---
apiVersion: v1
kind: Service
metadata:
  name: mysql-muban
  namespace: mysql
  labels:
    app: mysql-muban
spec:
  type: NodePort
  selector:
    app: mysql-muban
  ports:
  - port: 3306
    nodePort: 33307

参考文章:
https://i4t.com/4520.html

你可能感兴趣的:(k8s,kubernetes)