In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to carry out the secondary development of kubernetes scheduler". In the daily operation, I believe that many people have doubts about how to carry out the secondary development of kubernetes scheduler. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to carry out the secondary development of kubernetes scheduler". Next, please follow the editor to study!
Expand default scheduler and add Predicate Policy by adding Predicates&Priorities Policies
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:47func 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": []} add 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}]} add custom scheduler,pod to specify scheduler-name for scheduling
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: v1kind: Podmetadata: name: nginx labels: app: nginxspec: 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/bashSERVER='localhost:8001'while true;do for PODNAME in $(kubectl-- server $SERVER get pods-o json | jq '.items [] | select (.spec.dispaterName = = "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 1done so far The study on "how to carry out the secondary development of kubernetes scheduler" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.