【Kubernetes】配置自定義的 kube-scheduler 調度規則

在最近一次 K8s 環境的維護中,發現多個 Pod 使用相同鏡像時,調度到固定節點的問題導致集群節點資源分配不均的情況。 啟用調度器的打分日志后發現這一現象是由 ImageLocality 打分策略所引起的(所有的節點中,只有一個節點有運行該 pod 的鏡像,所以這個節點調度器打分最高); 最終,通過禁用該插件成功解決調度不均勻的問題。在此,我想分享這一經驗,希望能夠對大家有所幫助!

1、自定義配置文件

# vi /etc/kubernetes/config.yaml
# 此處禁用 ImageLocality 打分插件(設置權重為 0)
...
apiVersion: kubescheduler.config.k8s.io/v1
kind: KubeSchedulerConfiguration
clientConnection:kubeconfig: /etc/kubernetes/scheduler.conf
profiles:- schedulerName: default-schedulerplugins:multiPoint:enabled:- name: ImageLocalityweight: 0
...

  • (可跳過)禁用打分插件的第二種方式,根據實際情況進行配置
# vi /etc/kubernetes/config.yaml 
apiVersion: kubescheduler.config.k8s.io/v1beta1
kind: KubeSchedulerConfiguration
clientConnection:kubeconfig: /etc/kubernetes/scheduler.conf
profiles:- schedulerName: default-schedulerplugins:score:disabled:- name: ImageLocality

2、配置 kube-scheduler

# 修改 kube-scheduler.yaml
# 在 spec.containers[0].command 添加參數;并掛載配置文件
vi /etc/kubernetes/manifests/kube-scheduler.yaml
...
- --config=/etc/kubernetes/config.yaml
...- mountPath: /etc/kubernetes/config.yaml      # 添加掛載name: configreadOnly: true
...- hostPath:path: /etc/kubernetes/config.yamltype: FileOrCreatename: config
...# 等待 kube-scheduler 自動重啟
kubectl get pod -n kube-system# 完整 kube-scheduler.yaml 如下
apiVersion: v1
kind: Pod
metadata:creationTimestamp: nulllabels:component: kube-schedulertier: control-planename: kube-schedulernamespace: kube-system
spec:containers:- command:- kube-scheduler- --authentication-kubeconfig=/etc/kubernetes/scheduler.conf- --authorization-kubeconfig=/etc/kubernetes/scheduler.conf- --bind-address=127.0.0.1- --kubeconfig=/etc/kubernetes/scheduler.conf- --leader-elect=true- --config=/etc/kubernetes/config.yaml- --v=10image: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.31.0imagePullPolicy: IfNotPresentlivenessProbe:failureThreshold: 8httpGet:host: 127.0.0.1path: /healthzport: 10259scheme: HTTPSinitialDelaySeconds: 10periodSeconds: 10timeoutSeconds: 15name: kube-schedulerresources:requests:cpu: 100mstartupProbe:failureThreshold: 24httpGet:host: 127.0.0.1path: /healthzport: 10259scheme: HTTPSinitialDelaySeconds: 10periodSeconds: 10timeoutSeconds: 15volumeMounts:- mountPath: /etc/kubernetes/scheduler.confname: kubeconfigreadOnly: true- mountPath: /etc/kubernetes/config.yamlname: configreadOnly: truehostNetwork: truepriority: 2000001000priorityClassName: system-node-criticalsecurityContext:seccompProfile:type: RuntimeDefaultvolumes:- hostPath:path: /etc/kubernetes/scheduler.conftype: FileOrCreatename: kubeconfig- hostPath:path: /etc/kubernetes/config.yamltype: FileOrCreatename: config
status: {}

3、驗證自定義配置生效

# kube-scheduler 日志如何開啟可見博客
# https://blog.csdn.net/mm1234556/article/details/148686859# 通過日志查看配置文件
kubectl logs -n kube-system kube-scheduler-master |grep -A50 apiVersion:

# 手動創建一個 pod,查看 kube-scheduler 日志中調度的打分細節
kubectl logs kube-scheduler-master -n kube-system |grep -A10 score# 詳細日志,最終調度到 node04 節點上
I0623 01:28:10.258309       1 resource_allocation.go:78] mysql-server-68468bcd96-j66bj -> node02: NodeResourcesBalancedAllocation, map of allocatable resources map[cpu:28000 memory:32772333568], map of requested resources map[cpu:3200 memory:5674337280] ,score 94,
I0623 01:28:10.258309       1 resource_allocation.go:78] mysql-server-68468bcd96-j66bj -> node01: NodeResourcesBalancedAllocation, map of allocatable resources map[cpu:28000 memory:32772333568], map of requested resources map[cpu:3820 memory:6427770880] ,score 94,
I0623 01:28:10.258312       1 resource_allocation.go:78] mysql-server-68468bcd96-j66bj -> node04: NodeResourcesBalancedAllocation, map of allocatable resources map[cpu:8000 memory:32122888192], map of requested resources map[cpu:1050 memory:1468006400] ,score 91,
I0623 01:28:10.258334       1 resource_allocation.go:78] mysql-server-68468bcd96-j66bj -> node02: NodeResourcesLeastAllocated, map of allocatable resources map[cpu:28000 memory:32772333568], map of requested resources map[cpu:3200 memory:5674337280] ,score 85,
I0623 01:28:10.258339       1 resource_allocation.go:78] mysql-server-68468bcd96-j66bj -> node04: NodeResourcesLeastAllocated, map of allocatable resources map[cpu:8000 memory:32122888192], map of requested resources map[cpu:1050 memory:1468006400] ,score 90,
I0623 01:28:10.258338       1 resource_allocation.go:78] mysql-server-68468bcd96-j66bj -> node01: NodeResourcesLeastAllocated, map of allocatable resources map[cpu:28000 memory:32772333568], map of requested resources map[cpu:3820 memory:6427770880] ,score 83,
I0623 01:28:10.258375       1 generic_scheduler.go:504] Plugin NodePreferAvoidPods scores on test-5/mysql-server-68468bcd96-j66bj => [{node01 1000000} {node04 1000000} {node02 1000000}]
I0623 01:28:10.258384       1 generic_scheduler.go:504] Plugin PodTopologySpread scores on test-5/mysql-server-68468bcd96-j66bj => [{node01 0} {node04 0} {node02 0}]
I0623 01:28:10.258389       1 generic_scheduler.go:504] Plugin TaintToleration scores on test-5/mysql-server-68468bcd96-j66bj => [{node01 100} {node04 100} {node02 100}]
I0623 01:28:10.258393       1 generic_scheduler.go:504] Plugin NodeResourcesBalancedAllocation scores on test-5/mysql-server-68468bcd96-j66bj => [{node01 94} {node04 91} {node02 94}]
I0623 01:28:10.258396       1 generic_scheduler.go:504] Plugin InterPodAffinity scores on test-5/mysql-server-68468bcd96-j66bj => [{node01 0} {node04 0} {node02 0}]
I0623 01:28:10.258400       1 generic_scheduler.go:504] Plugin NodeResourcesLeastAllocated scores on test-5/mysql-server-68468bcd96-j66bj => [{node01 83} {node04 90} {node02 85}]
I0623 01:28:10.258404       1 generic_scheduler.go:504] Plugin NodeAffinity scores on test-5/mysql-server-68468bcd96-j66bj => [{node01 0} {node04 0} {node02 0}]
I0623 01:28:10.258409       1 generic_scheduler.go:560] Host node01 => Score 1000277
I0623 01:28:10.258412       1 generic_scheduler.go:560] Host node04 => Score 1000281
I0623 01:28:10.258414       1 generic_scheduler.go:560] Host node02 => Score 1000279

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/88229.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/88229.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/88229.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

跟著AI學習C# Day21

📅 Day 21:動態類型與動態語言運行時(Dynamic Types & DLR) ? 學習目標: 理解什么是 dynamic 類型;掌握 dynamic 與 object 的區別;理解 DLR(Dynamic Language Runtime&#…

leetcode-3085.成為K字符串需要刪除的最小字符串數

題目描述 解題思路 這題不難想到需要統計每個字母的出現頻率,一共有26個字母,故cnt數組有26維。我們可以枚舉其中一種作為「刪除操作結束后出現頻率最低的字符」,將其設置為 c,那么所有頻率小于 c 的字符都會被刪除,所…

Android 中 解析 XML 文件的幾種方式

在 Android 開發中,解析 XML 文件有多種方式,每種方式都有其特點和適用場景。常見的 XML 解析方式有 DOM 解析、SAX 解析 和 XmlPullParser 解析。 一、xml 文件及數據類 1、xml 文件 將測試用 book.xml 文件放在項目的 app/src/main/assets 目錄下,文件內容如下:<lib…

python里的abc庫是什么東西

Python 中的 ABC&#xff1a;為什么你需要抽象基類&#xff1f;告別“假鴨子”&#xff0c;擁抱真抽象&#xff01; 你是不是經常在 Python 項目中感到困惑&#xff1a;我定義了一個類&#xff0c;希望它能被其他類繼承并實現某些特定功能&#xff0c;但又不想它被直接實例化&…

設計模式精講 Day 9:裝飾器模式(Decorator Pattern)

【設計模式精講 Day 9】裝飾器模式&#xff08;Decorator Pattern&#xff09; 文章內容 在軟件開發中&#xff0c;靈活擴展功能是提升系統可維護性和可復用性的關鍵。裝飾器模式作為一種結構型設計模式&#xff0c;為對象動態地添加職責&#xff0c;而無需通過繼承來實現。它…

瀏覽器無法訪問:Nginx下的基于域名的虛擬主機

檢查步驟如下&#xff1a; 1、nginx -t &#xff0c;檢查配置文件是否有語法錯誤 [root89 ~]# nginx -t nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok nginx: configuration file /opt/nginx/conf/nginx.conf test is successful # 可以看到 配置…

【appium】6.appium遇到的問題

1.appium-python-client 修改版本1.5 為5.1.1,后執行python程序時&#xff0c;提示&#xff1a; raise TypeError( TypeError: missing 1 required keyword-only argument: options (instance of driver options.Options class) 你遇到的錯誤&#xff1a; TypeError: missing…

C++法則3:使用拷貝和交換的賦值運算符自動就是異常安全的,且能正確處理自賦值。

C法則3&#xff1a;使用拷貝和交換的賦值運算符自動就是異常安全的&#xff0c;且能正確處理自賦值。 這條法則強調了使用"拷貝和交換"(Copy-and-Swap)慣用法來實現賦值運算符()的優點&#xff1a; 關鍵點 異常安全&#xff1a;拷貝和交換方法天然提供了強異常安全…

純血HarmonyOS5 打造小游戲實踐:掃雷(附源文件)

鴻蒙掃雷游戲的核心架構設計 鴻蒙OS掃雷游戲采用了MVC&#xff08;模型-視圖-控制器&#xff09;的架構思想&#xff0c;將游戲邏輯與UI展示分離&#xff0c;使得代碼結構清晰且易于維護。整個游戲由以下幾個核心部分構成&#xff1a; 數據模型設計 游戲的基礎數據模型是Cel…

Linux C語言的opendir如何獲取目錄下的隱藏文件

在 Linux 文件系統中&#xff0c;所謂隱藏文件是文件名以 . 開頭的文件&#xff08;例如 .bashrc、.git、.config 等&#xff09;。 在編程層面&#xff0c;opendir readdir 并不會自動排除隱藏文件。 只要你不在代碼中手動過濾&#xff0c;readdir 會把目錄下所有文件&#…

母線槽接頭過熱隱患難防?在線測溫方案實時守護電力安全

近年來&#xff0c;由于各種設備對電力的大力需求&#xff0c;并有逐年增加的趨勢&#xff0c;傳統電路接線方式在施工時越來越力不從心。系統一旦定型&#xff0c;后續想要簡化變更更是難上加難。母線槽方案因此興起&#xff0c;憑借多點連接&#xff08;接頭、插接頭、插接箱…

Windows本地部署wordpress

一、下載wordpress 地址&#xff1a;Download – WordPress.org 下載后解壓出來 二、下載小皮面板 地址&#xff1a;Windows版phpstudy下載 - 小皮面板(phpstudy) 下載后安裝 三、打開小皮面板&#xff0c;安裝對應內置應用 1、MySQL8&#xff08;注意要是8版本,卸載其他版本…

Android 性能優化

一、Android中檢測性能工具 Profiler —— 使用Profiler的CPU分析功能。 Method Tracing ———— 通過該方法,我們可以記錄應用運行過程中的方法調用情況,包括每個方法的執行時間、調用次數等。 Systrace 是Android平臺提供的一款工具,用于記錄短期內的設備活動。 Systra…

圖片壓縮工具 | Electron應用配合 commander 提供命令行調用功能

OPEN-IMAGE-TINY&#xff0c;一個基于 Electron VUE3 的圖片壓縮工具&#xff0c;項目開源地址&#xff1a;https://github.com/0604hx/open-image-tiny 功能描述 應用程序的命令行調用功能允許用戶通過終端&#xff08;如Windows的CMD/PowerShell或Linux/macOS的Terminal&am…

Linux》》Shell腳本 基本語法

執行腳本的三種方式 查找變量的過程 變量引用的順序》》先從當前進程查詢變量&#xff0c;如果當前進程沒有此變量&#xff0c;默認去父進程查找這個變量。如果查找到則返回&#xff0c;否則一直查找到 祖宗&#xff08;PID為1&#xff09;&#xff0c;還沒有&#xff0c;則就…

C#.VB.NET多線程,多用戶下獨立鎖和全局鎖的區別

以下代碼,每個客戶端都分配了一個鎖嗎? 用戶WebSocket信息類Public Class UserWebSocketInfoPublic Property SessionID As StringPublic Property WebSocket As WebSocketPublic Property LastResponseTime As DateTimePublic Property PendingHeartbeatCount As IntegerPubl…

無人機加速器模塊技術解析

一、加速器模塊的運行方式 1. 傳感器數據采集與融合 加速度計核心作用&#xff1a;測量三維線性加速度&#xff08;X/Y/Z軸&#xff09;&#xff0c;結合陀螺儀&#xff08;角速度&#xff09;和磁力計&#xff08;方向&#xff09;構成九軸姿態傳感器&#xff0c;實時輸出…

用html實現數字生命

<!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>數學粒子動畫</title><style>body {mar…

SQLite3 在嵌入式系統中的應用指南

SQLite3 在嵌入式系統中的應用指南 一、嵌入式系統中 SQLite3 的優勢 SQLite3 是嵌入式系統的理想數據庫解決方案&#xff0c;具有以下核心優勢&#xff1a; 特性嵌入式系統價值典型指標輕量級適合資源受限環境庫大小&#xff1a;500-700KB零配置無需數據庫管理員開箱即用無…

通義大模型與現有企業系統集成實戰《CRM案例分析與安全最佳實踐》

1. 集成架構設計 &#xff08;1&#xff09;混合部署架構演進 #mermaid-svg-eW4YPoU2fdbnT4xp {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-eW4YPoU2fdbnT4xp .error-icon{fill:#552222;}#mermaid-svg-eW4YPoU2f…