nodename
vim nodename.yaml apiVersion: v1
kind: Pod
metadata:name: nginxlabels:app: nginxspec:containers:- name: nginximage: nginxnodeName: k8s2 nodeName: k8s2 #找不到节点pod会出现pending,优先级最高
kubectl apply -f nodename.yamlkubectl get pod -o wide 
回收
kubectl delete -f nodename.yaml nodeselector
vim nodeselector.yaml apiVersion: v1
kind: Pod
metadata:name: nginx
spec:containers:- name: nginximage: nginximagePullPolicy: IfNotPresentnodeSelector:disktype: ssd
kubectl label nodes k8s4 disktype=ssdkubectl label nodes k8s3 disktype=ssd
kubectl apply -f nodeselector.yaml 
回收
kubectl delete -f nodeselector.yaml nodeaffinity
vim nodeaffinity.yaml apiVersion: v1
kind: Pod
metadata:name: node-affinity
spec:containers:- name: nginximage: nginxaffinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: disktypeoperator: Invalues:- ssd- fcpreferredDuringSchedulingIgnoredDuringExecution:- weight: 1preference:matchExpressions:- key: kubernetes.io/hostnameoperator: NotInvalues:- k8s3 kubectl apply -f nodeaffinity.yaml
kubectl describe pod node-affinity

回收
kubectl delete -f nodeaffinity.yaml podaffinity
vim podaffinity.yaml apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-deploymentlabels:app: nginx
spec:replicas: 3selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- name: nginximage: nginxaffinity:podAffinity:requiredDuringSchedulingIgnoredDuringExecution:- labelSelector:matchExpressions:- key: appoperator: Invalues:- nginxtopologyKey: "kubernetes.io/hostname" kubectl apply -f podaffinity.yamlkubectl get pod -o wide 
回收
kubectl delete -f podaffinity.yaml podantiaffinity
vim podantiaffinity.yaml apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-deploymentlabels:app: nginx
spec:replicas: 3selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- name: nginximage: nginxaffinity:podAntiAffinity:requiredDuringSchedulingIgnoredDuringExecution:- labelSelector:matchExpressions:- key: appoperator: Invalues:- nginxtopologyKey: "kubernetes.io/hostname" kubectl apply -f podantiaffinity.yamlkubectl get pod -o wide 
回收
kubectl delete -f podantiaffinity.yaml pod反亲和倾向满足
vim poda.yaml apiVersion: apps/v1
kind: Deployment
metadata:name: node-affinity
spec:replicas: 3selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:tolerations:- effect: NoScheduleoperator: Exists- effect: NoExecuteoperator: Existscontainers:- name: nginximage: nginxaffinity:podAntiAffinity:preferredDuringSchedulingIgnoredDuringExecution:- weight: 100podAffinityTerm:labelSelector:matchExpressions:- key: appoperator: Invalues:- nginxtopologyKey: kubernetes.io/hostnamenodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: disktypeoperator: Invalues:- ssd- sata kubectl apply -f poda.yamlkubectl get pod -o wide 
回收
kubectl delete -f poda.yaml Taints
vim taint.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: webname: web
spec:replicas: 3selector:matchLabels:app: webtemplate:metadata:labels:app: webspec:containers:- image: nginxname: nginx kubectl apply -f taint.yamlkubectl get pod -o wide 
设置taint
kubectl taint node k8s3 k1=v1:NoSchedulekubectl describe nodes k8s3 |grep Tain 
kubectl scale deployment web --replicas 6kubectl get pod -o wide 
kubectl taint node k8s3 k1=v1:NoExecutekubectl describe nodes k8s3 |grep Tain 
kubectl get pod -o wide 
回收
kubectl delete -f taint.yaml 设置 tolerations
vim taint.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: webname: web
spec:replicas: 6selector:matchLabels:app: webtemplate:metadata:labels:app: webspec:tolerations:- operator: Existseffect: NoSchedulecontainers:- image: nginxname: nginx kubectl apply -f taint.yamlkubectl get pod -o wide 
回收
kubectl delete -f taint.yaml 容忍所有taints
vim taint.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: webname: web
spec:replicas: 6selector:matchLabels:app: webtemplate:metadata:labels:app: webspec:tolerations:- operator: Existscontainers:- image: nginxname: nginx kubectl apply -f taint.yamlkubectl get pod -o wide 
回收
kubectl delete -f taint.yaml 删除taints
kubectl taint node k8s3 k1- cordon、drain、delete
kubectl create deployment demo --image nginx --replicas 3kubectl get pod -o wide 
kubectl cordon k8s3kubectl get node 
kubectl scale deployment demo --replicas 6kubectl get pod -o wide 
kubectl drain k8s3 --ignore-daemonsetskubectl get pod -o wide 
kubectl delete nodes k8s3kubectl get node 
k8s3节点重启kubelet服务重新加入集群
[root@k8s3 ~]# systemctl restart kubelet[root@k8s2 node]# kubectl get node 