九 pod:污点taint 与容忍度tolerations

目录

  • 一.系统环境
  • 二.前言
  • 三.污点taint
    • 3.1 污点taint概览
    • 3.2 给节点添加污点taint
  • 四.容忍度tolerations
    • 4.1 容忍度tolerations概览
    • 4.2 设置容忍度tolerations
一.系统环境服务器版本docker软件版本Kubernetes(k8s)集群版本CPU架构CentOS Linux release 7.4.1708 (Core)Docker version 20.10.12v1.21.9x86_64Kubernetes集群架构:k8scloude1作为master节点 , k8scloude2,k8scloude3作为worker节点
服务器操作系统版本CPU架构进程功能描述k8scloude1/192.168.110.130CentOS Linux release 7.4.1708 (Core)x86_64docker,kube-apiserver,etcd , kube-scheduler,kube-controller-manager,kubelet,kube-proxy , coredns,calicok8s master节点k8scloude2/192.168.110.129CentOS Linux release 7.4.1708 (Core)x86_64docker,kubelet,kube-proxy,calicok8s worker节点k8scloude3/192.168.110.128CentOS Linux release 7.4.1708 (Core)x86_64docker,kubelet,kube-proxy,calicok8s worker节点二.前言本文介绍污点taint 与容忍度tolerations,可以影响pod的调度 。
使用污点taint 与容忍度tolerations的前提是已经有一套可以正常运行的Kubernetes集群,关于Kubernetes(k8s)集群的安装部署,可以查看博客《Centos7 安装部署Kubernetes(k8s)集群》https://www.cnblogs.com/renshengdezheli/p/16686769.html
三.污点taint3.1 污点taint概览节点亲和性 是 Pod 的一种属性,它使 Pod 被吸引到一类特定的节点 (这可能出于一种偏好,也可能是硬性要求) 。污点(Taint) 则相反——它使节点能够排斥一类特定的 Pod 。
3.2 给节点添加污点taint给节点增加一个污点的语法如下:给节点 node1 增加一个污点 , 它的键名是 key1,键值是 value1,效果是 NoSchedule 。这表示只有拥有和这个污点相匹配的容忍度的 Pod 才能够被分配到 node1 这个节点 。
#污点的格式:键=值:NoSchedulekubectl taint nodes node1 key1=value1:NoSchedule#只有键没有值的话 , 格式为:键:NoSchedulekubectl taint nodes node1 key1:NoSchedule移除污点语法如下:
kubectl taint nodes node1 key1=value1:NoSchedule-节点的描述信息里有一个Taints字段,Taints字段表示节点有没有污点
[root@k8scloude1 deploy]# kubectl get nodes -o wideNAMESTATUSROLESAGEVERSIONINTERNAL-IPEXTERNAL-IPOS-IMAGEKERNEL-VERSIONCONTAINER-RUNTIMEk8scloude1Readycontrol-plane,master8dv1.21.0192.168.110.130<none>CentOS Linux 7 (Core)3.10.0-693.el7.x86_64docker://20.10.12k8scloude2Ready<none>8dv1.21.0192.168.110.129<none>CentOS Linux 7 (Core)3.10.0-693.el7.x86_64docker://20.10.12k8scloude3Ready<none>8dv1.21.0192.168.110.128<none>CentOS Linux 7 (Core)3.10.0-693.el7.x86_64docker://20.10.12[root@k8scloude1 deploy]# kubectl describe nodes k8scloude1Name:k8scloude1Roles:control-plane,masterLabels:beta.kubernetes.io/arch=amd64beta.kubernetes.io/os=linuxkubernetes.io/arch=amd64kubernetes.io/hostname=k8scloude1kubernetes.io/os=linuxnode-role.kubernetes.io/control-plane=node-role.kubernetes.io/master=node.kubernetes.io/exclude-from-external-load-balancers=Annotations:kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.socknode.alpha.kubernetes.io/ttl: 0projectcalico.org/IPv4Address: 192.168.110.130/24projectcalico.org/IPv4IPIPTunnelAddr: 10.244.158.64volumes.kubernetes.io/controller-managed-attach-detach: trueCreationTimestamp:Sun, 09 Jan 2022 16:19:06 +0800Taints:node-role.kubernetes.io/master:NoScheduleUnschedulable:false......查看节点是否有污点,Taints:node-role.kubernetes.io/master:NoSchedule表示k8s集群的master节点有污点,这是默认就存在的污点,这也是master节点为什么不能运行应用pod的原因 。
[root@k8scloude1 deploy]# kubectl describe nodes k8scloude2 | grep -i TaintsTaints:<none>[root@k8scloude1 deploy]# kubectl describe nodes k8scloude1 | grep -i TaintsTaints:node-role.kubernetes.io/master:NoSchedule[root@k8scloude1 deploy]# kubectl describe nodes k8scloude3 | grep -i TaintsTaints:<none>创建pod,nodeSelector:kubernetes.io/hostname: k8scloude1表示pod运行在标签为kubernetes.io/hostname=k8scloude1的节点上 。
关于pod的调度详细内容 , 请查看博客《pod(八):pod的调度——将 Pod 指派给节点》https://www.cnblogs.com/renshengdezheli/p/16863405.html
[root@k8scloude1 pod]# vim schedulepod4.yaml [root@k8scloude1 pod]# cat schedulepod4.yamlapiVersion: v1kind: Podmetadata:creationTimestamp: nulllabels:run: pod1name: pod1namespace: podspec:nodeSelector:kubernetes.io/hostname: k8scloude1containers:- image: nginximagePullPolicy: IfNotPresentname: pod1resources: {}ports:- name: httpcontainerPort: 80protocol: TCPhostPort: 80dnsPolicy: ClusterFirstrestartPolicy: Alwaysstatus: {}标签为kubernetes.io/hostname=k8scloude1的节点为k8scloude1节点

推荐阅读