八 pod:pod的调度——将 Pod 指派给节点( 三 )

k8scloude1是master节点 , master节点一般不运行应用pod,并且k8scloude1有污点,一般来说,pod是不运行在有污点的主机上的 , 如果强制调度上去的话,pod的状态应该是pending , 但是通过nodeName可以把一个pod调度到有污点的主机上正常运行的 , 比如nodeName指定pod运行在master上
[root@k8scloude1 pod]# kubectl get pods -o wideNAMEREADYSTATUSRESTARTSAGEIPNODENOMINATED NODEREADINESS GATESpod11/1Running047s10.244.158.81k8scloude1<none><none>[root@k8scloude1 pod]# kubectl delete pod pod1 --forcewarning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.pod "pod1" force deleted3.4 使用节点标签nodeSelector指定pod运行在哪个节点与很多其他 Kubernetes 对象类似,节点也有标签 。你可以手动地添加标签 。Kubernetes 也会为集群中所有节点添加一些标准的标签 。
通过为节点添加标签 , 你可以准备让 Pod 调度到特定节点或节点组上 。你可以使用这个功能来确保特定的 Pod 只能运行在具有一定隔离性,安全性或监管属性的节点上 。nodeSelector 是节点选择约束的最简单推荐形式 。你可以将 nodeSelector 字段添加到 Pod 的规约中设置你希望目标节点所具有的节点标签 。Kubernetes 只会将 Pod 调度到拥有你所指定的每个标签的节点上 。nodeSelector 提供了一种最简单的方法来将 Pod 约束到具有特定标签的节点上 。
3.4.1 查看标签查看节点node的标签,标签的格式:键值对:xxxx/yyyy.aaaa=456123,xxxx1/yyyy1.aaaa=456123,--show-labels参数显示标签
[root@k8scloude1 pod]# kubectl get nodes --show-labelsNAMESTATUSROLESAGEVERSIONLABELSk8scloude1Readycontrol-plane,master7d1hv1.21.0beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8scloude1,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=,node.kubernetes.io/exclude-from-external-load-balancers=k8scloude2Ready<none>7dv1.21.0beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8scloude2,kubernetes.io/os=linuxk8scloude3Ready<none>7dv1.21.0beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8scloude3,kubernetes.io/os=linux查看namespace的标签
[root@k8scloude1 pod]# kubectl get ns --show-labelsNAMESTATUSAGELABELSdefaultActive7d1hkubernetes.io/metadata.name=defaultkube-node-leaseActive7d1hkubernetes.io/metadata.name=kube-node-leasekube-publicActive7d1hkubernetes.io/metadata.name=kube-publickube-systemActive7d1hkubernetes.io/metadata.name=kube-systemns1Active6d5hkubernetes.io/metadata.name=ns1ns2Active6d5hkubernetes.io/metadata.name=ns2podActive4d2hkubernetes.io/metadata.name=pod查看pod的标签
[root@k8scloude1 pod]# kubectl get pod -A --show-labelsNAMESPACENAMEREADYSTATUSRESTARTSAGELABELSkube-systemcalico-kube-controllers-6b9fbfff44-4jzkj1/1Running127dk8s-app=calico-kube-controllers,pod-template-hash=6b9fbfff44kube-systemcalico-node-bdlgm1/1Running77dcontroller-revision-hash=6b57d9cd54,k8s-app=calico-node,pod-template-generation=1kube-systemcalico-node-hx8bk1/1Running77dcontroller-revision-hash=6b57d9cd54,k8s-app=calico-node,pod-template-generation=1kube-systemcalico-node-nsbfs1/1Running77dcontroller-revision-hash=6b57d9cd54,k8s-app=calico-node,pod-template-generation=1kube-systemcoredns-545d6fc579-7wm951/1Running77d1hk8s-app=kube-dns,pod-template-hash=545d6fc579kube-systemcoredns-545d6fc579-87q8j1/1Running77d1hk8s-app=kube-dns,pod-template-hash=545d6fc579kube-systemetcd-k8scloude11/1Running77d1hcomponent=etcd,tier=control-planekube-systemkube-apiserver-k8scloude11/1Running117d1hcomponent=kube-apiserver,tier=control-planekube-systemkube-controller-manager-k8scloude11/1Running77d1hcomponent=kube-controller-manager,tier=control-planekube-systemkube-proxy-599xh1/1Running77d1hcontroller-revision-hash=6795549d44,k8s-app=kube-proxy,pod-template-generation=1kube-systemkube-proxy-lpj8z1/1Running77d1hcontroller-revision-hash=6795549d44,k8s-app=kube-proxy,pod-template-generation=1kube-systemkube-proxy-zxlk91/1Running77d1hcontroller-revision-hash=6795549d44,k8s-app=kube-proxy,pod-template-generation=1kube-systemkube-scheduler-k8scloude11/1Running77d1hcomponent=kube-scheduler,tier=control-planekube-systemmetrics-server-bcfb98c76-k5dmj1/1Running66d5hk8s-app=metrics-server,pod-template-hash=bcfb98c763.4.2 创建标签以node-role.kubernetes.io/control-plane= 标签为例 , 键是node-role.kubernetes.io/control-plane , 值为空 。
创建标签的语法:kubectl label 对象类型 对象名 键=值
给k8scloude2节点设置标签
[root@k8scloude1 pod]# kubectl label nodes k8scloude2 k8snodename=k8scloude2node/k8scloude2 labeled[root@k8scloude1 pod]# kubectl get nodes --show-labelsNAMESTATUSROLESAGEVERSIONLABELSk8scloude1Readycontrol-plane,master7d1hv1.21.0beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8scloude1,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=,node.kubernetes.io/exclude-from-external-load-balancers=k8scloude2Ready<none>7d1hv1.21.0beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,k8snodename=k8scloude2,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8scloude2,kubernetes.io/os=linuxk8scloude3Ready<none>7d1hv1.21.0beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8scloude3,kubernetes.io/os=linux

推荐阅读