nodename
vim nodename.yamlapiVersion: v1
kind: Pod
metadata:name: nginxlabels:app: nginxspec:containers:- name: nginximage: nginxnodeName: k8s2nodeName: k8s2 #找不到节点pod会出现pending,优先级最高
kubectl apply -f nodename.yamlkubectl get pod -o wide
回收
kubectl delete -f nodename.yamlnodeselector
vim nodeselector.yamlapiVersion: 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.yamlnodeaffinity
vim nodeaffinity.yamlapiVersion: 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:- k8s3kubectl apply -f nodeaffinity.yaml
kubectl describe  pod node-affinity

回收
kubectl delete -f nodeaffinity.yamlpodaffinity
vim podaffinity.yamlapiVersion: 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.yamlpodantiaffinity
vim podantiaffinity.yamlapiVersion: 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.yamlpod反亲和倾向满足
vim poda.yamlapiVersion: 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- satakubectl apply -f poda.yamlkubectl get pod -o wide
回收
kubectl delete -f poda.yamlTaints
vim taint.yamlapiVersion: apps/v1
kind: Deployment
metadata:labels:app: webname: web
spec:replicas: 3selector:matchLabels:app: webtemplate:metadata:labels:app: webspec:containers:- image: nginxname: nginxkubectl 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.yamlapiVersion: 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: nginxkubectl apply -f taint.yamlkubectl get pod -o wide
回收
kubectl delete -f taint.yaml容忍所有taints
vim taint.yamlapiVersion: apps/v1
kind: Deployment
metadata:labels:app: webname: web
spec:replicas: 6selector:matchLabels:app: webtemplate:metadata:labels:app: webspec:tolerations:- operator: Existscontainers:- image: nginxname: nginxkubectl 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