Kubernetes 调度器 - 调度说明

1、Kubernetes 调度器 - 调度说明
  https://blog.csdn.net/wtl1992/article/details/104982548
2、Kubernetes 调度器 - 调度亲和性
   https://blog.csdn.net/wtl1992/article/details/104983234
3、Kubernetes 调度器 - 污点
  https://blog.csdn.net/wtl1992/article/details/105041339
4、Kubernetes 调度器 - 固定节点
  https://blog.csdn.net/wtl1992/article/details/105043138
 
案例:

  节点亲和性
    pod.spec.nodeAffinity
    preferredDuringSchedulingIgnoredDuringExecution:软策略
    requiredDuringSchedulingIgnoredDuringExecution:硬策略

指定到 kubernetes.io/hostname=xgcloud-ops-k8s-cluster-2.novalocal  有这个标签的机器


 

 

 requiredDuringSchedulingIgnoredDuringExecution:硬策略

复制代码
[root@xgcloud-ops-k8s-cluster-4 nodeaff]# cat pod2.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
    version: v1
spec:
  containers: 
  -  name: app
     image: nginx
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - xgcloud-ops-k8s-cluster-2.novalocal
复制代码

 

 

 preferredDuringSchedulingIgnoredDuringExecution:软策略

复制代码
[root@xgcloud-ops-k8s-cluster-4 nodeaff]# cat pod3.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod3
  labels:
    app: myapp-pod3
    version: v1
spec:
  containers: 
  -  name: myapp-pod3
     image: nginx
  affinity:
    nodeAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - xgcloud-ops-k8s-cluster-5.novalocal
复制代码

kubectl apply -f pod3.yaml

kubectl get pod -o wide

 

 指定了xgcloud-ops-k8s-cluster-5.novalocal,没有这个node,但是还是成功running,调度到了 xgcloud-ops-k8s-cluster-1.novalocal

 

preferredDuringSchedulingIgnoredDuringExecution:软策略
requiredDuringSchedulingIgnoredDuringExecution:硬策略

一起进行配置:

复制代码
[root@xgcloud-ops-k8s-cluster-4 nodeaff]# cat pod4.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod4
  labels:
    app: myapp-pod4
    version: v1
spec:
  containers: 
  -  name: myapp-pod4
     image: nginx
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - xgcloud-ops-k8s-cluster-3.novalocal
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - xgcloud-ops-k8s-cluster-5.novalocal
复制代码

kubectl apply -f pod4.yaml

kubectl describe pod/myapp-pod4

kubectl get pod -o wide

 

 

 pod亲和性

pod.spec.affiffiffinity.podAffiffiffinity/podAntiAffiffiffinity
 
没找到别的容器,暂时不测了,用法差不多

 

 

 

跑一个pod2

复制代码
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
    version: v1
spec:
  containers: 
  -  name: app
     image: nginx
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - xgcloud-ops-k8s-cluster-2.novalocal
复制代码

跑一个pod3跟他pod亲和

复制代码
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod3
  labels:
    app: myapp-pod3
    version: v1
spec:
  containers: 
  - command:
    - "sleep"
    - "3600"
    name: myapp-pod3
    image: busybox
  affinity:
    podAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: app
            operator: In
            values:
            - myapp
        topologyKey: kubernetes.io/hostname 
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        podAffinityTerm:
          labelSelector:
            matchExpressions:      
            - key: app
              operator: In      
              values:       
              - myapp-pod4       
          topologyKey: kubernetes.io/hostname
复制代码

 

 

 

 

 

 

 

posted @   大川哥  阅读(261)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示