已解决
kubernetes集群编排——k8s调度
来自网友在路上 161861提问 提问时间:2023-11-08 07:01:06阅读次数: 61
最佳答案 问答题库618位专家为你答疑解惑
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
查看全文
99%的人还看了
相似问题
- 〖大前端 - 基础入门三大核心之JS篇㊲〗- DOM改变元素节点的css样式、HTML属性
- Java 算法篇-链表的经典算法:判断回文链表、判断环链表与寻找环入口节点(“龟兔赛跑“算法实现)
- 代码随想录二刷 | 链表 | 删除链表的倒数第N个节点
- 节点导纳矩阵
- bhosts 显示节点 “unreach“ 状态
- 电子电器架构 —— 车载网关边缘节点总线转换
- 〖大前端 - 基础入门三大核心之JS篇㊳〗- DOM访问元素节点
- 第四天||24. 两两交换链表中的节点 ● 19.删除链表的倒数第N个节点 ● 面试题 02.07. 链表相交 ● 142.环形链表II
- CS224W5.1——消息传递和节点分类
- Vue报错解决Error in v-on handler: “Error: 无效的节点选择器:#div1“
猜你感兴趣
版权申明
本文"kubernetes集群编排——k8s调度":http://eshow365.cn/6-35116-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!