久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

怎么對kubernetes scheduler進行二次開發(fā)

161次閱讀
沒有評論

共計 3737 個字符,預(yù)計需要花費 10 分鐘才能閱讀完成。

這篇文章主要介紹“怎么對 kubernetes scheduler 進行二次開發(fā)”,在日常操作中,相信很多人在怎么對 kubernetes scheduler 進行二次開發(fā)問題上存在疑惑,丸趣 TV 小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么對 kubernetes scheduler 進行二次開發(fā)”的疑惑有所幫助!接下來,請跟著丸趣 TV 小編一起來學(xué)習(xí)吧!

通過新增 Predicates Priorities Policies 來擴展 default scheduler 新增 Predicate Policy

predicate Interface

plugin/pkg/scheduler/algorithm/types.go:31
// FitPredicate is a function that indicates if a pod fits into an existing node.
// The failure information is given by the error.
type FitPredicate func(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, []PredicateFailureReason, error)

Implement a predicate func

func PodFitsHostNew(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, []algorithm.PredicateFailureReason, error) {if len(pod.Spec.NodeName) == 0 {
 return true, nil, nil
 node := nodeInfo.Node()
 if node == nil {return false, nil, fmt.Errorf( node not found)
 if pod.Spec.NodeName == node.Name {
 return true, nil, nil
 return false, []algorithm.PredicateFailureReason{ErrPodNotMatchHostName}, nil
}

register the custom predicate policy with a custom name

plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go:47
func init() {factory.RegisterAlgorithmProvider(factory.DefaultProvider, defaultPredicates(), defaultPriorities())
 // Cluster autoscaler friendly scheduling algorithm.
 factory.RegisterAlgorithmProvider(ClusterAutoscalerProvider, defaultPredicates(),
 copyAndReplace(defaultPriorities(),  LeastRequestedPriority ,  MostRequestedPriority ))
 factory.RegisterFitPredicate(CustomPredicatePolicy , predicates.PodFitsHostNew)
}

rebuild kube-scheduler and restart with flag of –policy-config-file

kube-scheduler xxxx –policy-config-file=/var/lib/kube-scheduler/policy.config

the content of –policy-config-file specified file

/var/lib/kube-scheduler/policy.config
 kind  :  Policy ,
 apiVersion  :  v1 ,
 predicates  : [ { name  :  CustomPredicatePolicy}
 ],
 priorities  : [ ]
}

新增 Priority Policy

Priority Interface

/Users/garnett/workspace/go/src/k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/types.go
// PriorityMapFunction is a function that computes per-node results for a given node.
type PriorityMapFunction func(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (schedulerapi.HostPriority, error)

Implement a predicate func

register the custom predicate policy with a custom name

rebuild kube-scheduler and restart with flag of –policy-config-file

the content of –policy-config-file specified file

/var/lib/kube-scheduler/policy.config
 kind  :  Policy ,
 apiVersion  :  v1 ,
 predicates  : [ ],
 priorities  : [ { name  :  CumtomPriorityPolicy ,  weight  : 1}
 ]
}

新增 custom scheduler,pod 指定 scheduler-name 進行調(diào)度

A custom scheduler can be written in any language and can be as simple or complex as you need.

Specify the“scheduleName”in pod.spec

apiVersion: v1
kind: Pod
metadata:
 name: nginx
 labels:
 app: nginx
spec:
 schedulerName: my-scheduler
 containers:
 - name: nginx
 image: nginx:1.10

Here is a very simple example of a custom scheduler written in Bash that assigns a node randomly. Note that you need to run this along with kubectl proxy for it to work.

kubectl proxy –port=8001

#!/bin/bash
SERVER= localhost:8001 
while true;
 for PODNAME in $(kubectl --server $SERVER get pods -o json | jq  .items[] | select(.spec.schedulerName ==  my-scheduler) | select(.spec.nodeName == null) | .metadata.name  | tr -d  )
 do
 NODES=($(kubectl --server $SERVER get nodes -o json | jq  .items[].metadata.name  | tr -d  ))
 NUMNODES=${#NODES[@]}
 CHOSEN=${NODES[$[ $RANDOM % $NUMNODES ]]}
 curl --header  Content-Type:application/json  --request POST --data  {apiVersion : v1 ,  kind :  Binding ,  metadata : { name :  $PODNAME},  target : { apiVersion :  v1 ,  kind 
:  Node ,  name :  $CHOSEN }}  http://$SERVER/api/v1/namespaces/default/pods/$PODNAME/binding/
 echo  Assigned $PODNAME to $CHOSEN 
 done
 sleep 1
done

到此,關(guān)于“怎么對 kubernetes scheduler 進行二次開發(fā)”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注丸趣 TV 網(wǎng)站,丸趣 TV 小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

正文完
 
丸趣
版權(quán)聲明:本站原創(chuàng)文章,由 丸趣 2023-08-16發(fā)表,共計3737字。
轉(zhuǎn)載說明:除特殊說明外本站除技術(shù)相關(guān)以外文章皆由網(wǎng)絡(luò)搜集發(fā)布,轉(zhuǎn)載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 新邵县| 建德市| 会理县| 肃北| 祁门县| 元朗区| 晋中市| 乡宁县| 蓬安县| 绥德县| 甘德县| 尼玛县| 台前县| 乌兰浩特市| 黄大仙区| 泗阳县| 博野县| 井研县| 黎城县| 会泽县| 德化县| 岚皋县| 志丹县| 婺源县| 东乌珠穆沁旗| 固镇县| 田东县| 丰宁| 湘乡市| 西林县| 太保市| 安陆市| 仁怀市| 西盟| 平塘县| 雅安市| 微山县| 襄垣县| 剑川县| 长沙县| 泰安市|