kubernetes集群编排——k8s调度

编程入门 行业动态 更新时间:2024-10-25 22:26:29

kubernetes<a href=https://www.elefans.com/category/jswz/34/1771240.html style=集群编排——k8s调度"/>

kubernetes集群编排——k8s调度

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

更多推荐

kubernetes集群编排——k8s调度

本文发布于:2023-11-16 00:50:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1610429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:集群   kubernetes   k8s

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!