website/_site/v1.1/docs/devel/scheduler_algorithm/index.html

175 lines
11 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!Doctype html>
<html id="docs">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/css/styles.css"/>
<script src="/js/script.js"></script>
<script src="/js/jquery-2.2.0.min.js"></script>
<script src="/js/non-mini.js"></script>
<title>Kubernetes - Scheduler Algorithm in Kubernetes</title>
</head>
<body>
<div id="cellophane" onclick="kub.toggleMenu()"></div>
<header>
<a href="/" class="logo"></a>
<div class="nav-buttons" data-auto-burger="primary">
<a href="/docs" class="button" id="viewDocs">View Documentation</a>
<a href="/get-started" class="button" id="tryKubernetes">Try Kubernetes</a>
<button id="hamburger" onclick="kub.toggleMenu()" data-auto-burger-exclude><div></div></button>
</div>
<nav id="mainNav">
<main data-auto-burger="primary">
<div class="nav-box">
<h3><a href="">Get Started</a></h3>
<p>Built for a multi-cloud world, public, private or hybrid. Seamlessly roll out new features.</p>
</div>
<div class="nav-box">
<h3><a href="">Documentation</a></h3>
<p>Pellentesque in ipsum id orci porta dapibus. Nulla porttitor accumsan tincidunt. </p>
</div>
<div class="nav-box">
<h3><a href="">Community</a></h3>
<p>Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui. </p>
</div>
<div class="nav-box">
<h3><a href="">Blog</a></h3>
<p>Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Quisque velit nisi, pretium ut lacinia in. </p>
</div>
</main>
<main data-auto-burger="primary">
<div class="left">
<h5 class="github-invite">Interested in hacking on the core Kubernetes code base?</h5>
<a href="" class="button">View On Github</a>
</div>
<div class="right">
<h5 class="github-invite">Explore the community</h5>
<div class="social">
<a href="https://twitter.com/kubernetesio" class="Twitter"><span>twitter</span></a>
<a href="https://github.com/kubernetes/kubernetes" class="github"><span>Github</span></a>
<a href="http://slack.k8s.io/" class="slack"><span>Slack</span></a>
<a href="http://stackoverflow.com/questions/tagged/kubernetes" class="stack-overflow"><span>stackoverflow</span></a>
<a href="https://groups.google.com/forum/#!forum/google-containers" class="mailing-list"><span>Mailing List</span></a>
</div>
</div>
<div class="clear" style="clear: both"></div>
</main>
</nav>
</header>
<!-- HERO -->
<section id="hero" class="light-text">
<h1></h1>
<h5></h5>
<div id="vendorStrip" class="light-text">
<ul>
<li><a href="/v1.1/">GUIDES</a></li>
<li><a href="/v1.1/reference">REFERENCE</a></li>
<li><a href="/v1.1/samples">SAMPLES</a></li>
<li><a href="/v1.1/support">SUPPORT</a></li>
</ul>
<div class="dropdown">
<div class="readout"></div>
<a href="/v1.1">Version 1.1</a>
<a href="/v1.0">Version 1.0</a>
</div>
<input type="text" id="search" placeholder="Search the docs">
</div>
</section>
<section id="encyclopedia">
<div id="docsToc">
<div class="pi-accordion">
</div> <!-- /pi-accordion -->
</div> <!-- /docsToc -->
<div id="docsContent">
<h1>Scheduler Algorithm in Kubernetes</h1>
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
<!-- END MUNGE: UNVERSIONED_WARNING -->
<h1 id="scheduler-algorithm-in-kubernetes">Scheduler Algorithm in Kubernetes</h1>
<p>For each unscheduled Pod, the Kubernetes scheduler tries to find a node across the cluster according to a set of rules. A general introduction to the Kubernetes scheduler can be found at <a href="scheduler.html">scheduler.md</a>. In this document, the algorithm of how to select a node for the Pod is explained. There are two steps before a destination node of a Pod is chosen. The first step is filtering all the nodes and the second is ranking the remaining nodes to find a best fit for the Pod.</p>
<h2 id="filtering-the-nodes">Filtering the nodes</h2>
<p>The purpose of filtering the nodes is to filter out the nodes that do not meet certain requirements of the Pod. For example, if the free resource on a node (measured by the capacity minus the sum of the resource requests of all the Pods that already run on the node) is less than the Pods required resource, the node should not be considered in the ranking phase so it is filtered out. Currently, there are several “predicates” implementing different filtering policies, including:</p>
<ul>
<li><code>NoDiskConflict</code>: Evaluate if a pod can fit due to the volumes it requests, and those that are already mounted.</li>
<li><code>PodFitsResources</code>: Check if the free resource (CPU and Memory) meets the requirement of the Pod. The free resource is measured by the capacity minus the sum of requests of all Pods on the node. To learn more about the resource QoS in Kubernetes, please check <a href="../proposals/resource-qos.html">QoS proposal</a>.</li>
<li><code>PodFitsHostPorts</code>: Check if any HostPort required by the Pod is already occupied on the node.</li>
<li><code>PodFitsHost</code>: Filter out all nodes except the one specified in the PodSpecs NodeName field.</li>
<li><code>PodSelectorMatches</code>: Check if the labels of the node match the labels specified in the Pods <code>nodeSelector</code> field (<a href="../user-guide/node-selection/">Here</a> is an example of how to use <code>nodeSelector</code> field).</li>
<li><code>CheckNodeLabelPresence</code>: Check if all the specified labels exist on a node or not, regardless of the value.</li>
</ul>
<p>The details of the above predicates can be found in <a href="http://releases.k8s.io/release-1.1/plugin/pkg/scheduler/algorithm/predicates/predicates.go">plugin/pkg/scheduler/algorithm/predicates/predicates.go</a>. All predicates mentioned above can be used in combination to perform a sophisticated filtering policy. Kubernetes uses some, but not all, of these predicates by default. You can see which ones are used by default in <a href="http://releases.k8s.io/release-1.1/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go">plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go</a>.</p>
<h2 id="ranking-the-nodes">Ranking the nodes</h2>
<p>The filtered nodes are considered suitable to host the Pod, and it is often that there are more than one nodes remaining. Kubernetes prioritizes the remaining nodes to find the “best” one for the Pod. The prioritization is performed by a set of priority functions. For each remaining node, a priority function gives a score which scales from 0-10 with 10 representing for “most preferred” and 0 for “least preferred”. Each priority function is weighted by a positive number and the final score of each node is calculated by adding up all the weighted scores. For example, suppose there are two priority functions, <code>priorityFunc1</code> and <code>priorityFunc2</code> with weighting factors <code>weight1</code> and <code>weight2</code> respectively, the final score of some NodeA is:</p>
<pre><code>finalScoreNodeA = (weight1 * priorityFunc1) + (weight2 * priorityFunc2)
</code></pre>
<p>After the scores of all nodes are calculated, the node with highest score is chosen as the host of the Pod. If there are more than one nodes with equal highest scores, a random one among them is chosen.</p>
<p>Currently, Kubernetes scheduler provides some practical priority functions, including:</p>
<ul>
<li><code>LeastRequestedPriority</code>: The node is prioritized based on the fraction of the node that would be free if the new Pod were scheduled onto the node. (In other words, (capacity - sum of requests of all Pods already on the node - request of Pod that is being scheduled) / capacity). CPU and memory are equally weighted. The node with the highest free fraction is the most preferred. Note that this priority function has the effect of spreading Pods across the nodes with respect to resource consumption.</li>
<li><code>CalculateNodeLabelPriority</code>: Prefer nodes that have the specified label.</li>
<li><code>BalancedResourceAllocation</code>: This priority function tries to put the Pod on a node such that the CPU and Memory utilization rate is balanced after the Pod is deployed.</li>
<li><code>CalculateSpreadPriority</code>: Spread Pods by minimizing the number of Pods belonging to the same service on the same node.</li>
<li><code>CalculateAntiAffinityPriority</code>: Spread Pods by minimizing the number of Pods belonging to the same service on nodes with the same value for a particular label.</li>
</ul>
<p>The details of the above priority functions can be found in <a href="http://releases.k8s.io/release-1.1/plugin/pkg/scheduler/algorithm/priorities/">plugin/pkg/scheduler/algorithm/priorities</a>. Kubernetes uses some, but not all, of these priority functions by default. You can see which ones are used by default in <a href="http://releases.k8s.io/release-1.1/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go">plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go</a>. Similar as predicates, you can combine the above priority functions and assign weight factors (positive number) to them as you want (check <a href="scheduler.html">scheduler.md</a> for how to customize).</p>
<!-- BEGIN MUNGE: IS_VERSIONED -->
<!-- TAG IS_VERSIONED -->
<!-- END MUNGE: IS_VERSIONED -->
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
<p><a href=""><img src="https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/devel/scheduler_algorithm.md?pixel" alt="Analytics" /></a>
<!-- END MUNGE: GENERATED_ANALYTICS --></p>
</div>
</section>
<footer>
<main class="light-text">
<nav>
<a href="/getting-started.html">Getting Started</a>
<a href="/docs.html">Documentation</a>
<a href="http://blog.kubernetes.io/">Blog</a>
<a href="/foobang.html">Community</a>
</nav>
<div class="social">
<a href="https://twitter.com/kubernetesio" class="twitter"><span>twitter</span></a>
<a href="https://github.com/kubernetes/kubernetes" class="github"><span>Github</span></a>
<a href="http://slack.k8s.io/" class="slack"><span>Slack</span></a>
<a href="http://stackoverflow.com/questions/tagged/kubernetes" class="stack-overflow"><span>stackoverflow</span></a>
<a href="https://groups.google.com/forum/#!forum/google-containers" class="mailing-list"><span>Mailing List</span></a>
<label for="wishField">I wish this page <input type="text" id="wishField" name="wishField" placeholder="made better textfield suggestions"></label>
</div>
<div class="center">&copy; 2016 Kubernetes</div>
</main>
</footer>
</body>
</html>